Advertisement
devsaider

TransformicePacket.java

Jan 28th, 2016
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package com.nanomice.nanomice;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.ByteArrayOutputStream;
  5. import java.io.DataInputStream;
  6. import java.io.DataOutputStream;
  7. import java.io.IOException;
  8.  
  9. /**
  10.  *
  11.  * @author Ruslan Devsaider <me@devsaider.ru>
  12.  */
  13. public class TransformicePacket {
  14.     public ByteArrayOutputStream rawb = new ByteArrayOutputStream();
  15.     public DataOutputStream b = new DataOutputStream(rawb);
  16.     public final int CC;
  17.     public final int C;
  18.    
  19.     private static final int[] SECRET_KEY = {19, 41, 50, 15, 47, 56, 5, 49, 33, 36, 109, 72, 112, 109, 86, 116, 97, 98, 88, 74};
  20.        
  21.     public TransformicePacket(int C, int CC) throws IOException {
  22.         this.C = C;
  23.         this.CC = CC;
  24.         this.b.writeByte(C);
  25.         this.b.writeByte(CC);
  26.     }
  27.    
  28.     static DataInputStream decode(int fingerprint, DataInputStream dis) throws IOException {
  29.         ByteArrayOutputStream rawnewdis = new ByteArrayOutputStream();
  30.         DataOutputStream newdis = new DataOutputStream(rawnewdis);
  31.         while (dis.available() > 0) {
  32.             fingerprint = (fingerprint + 1) % SECRET_KEY.length;
  33.             newdis.write(dis.readByte() ^ SECRET_KEY[fingerprint]);
  34.         }
  35.         return new DataInputStream(new ByteArrayInputStream(rawnewdis.toByteArray()));
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement