Advertisement
forextheblack

RC4

Nov 23rd, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1.     private int i = 0;
  2.     private int j = 0;
  3.     private int[] Table;
  4.    
  5.     public HabboRC4() {
  6.         Table = new int[0x0100];
  7.     }
  8.    
  9.     public void init(final byte[] Key) {
  10.         int k = Key.length;
  11.         this.i = 0;
  12.        
  13.         while(this.i < 0x0100) {
  14.             this.Table[this.i] = this.i;
  15.             this.i++;
  16.         }
  17.         this.j = 0;
  18.         this.i = 0;
  19.         while (this.i < 0x0100)
  20.         {
  21.             this.j = (((this.j + this.Table[this.i]) + Key[(this.i % k)]) % 0x0100);
  22.             this.mk(this.i, this.j);
  23.             this.i++;
  24.         };
  25.         this.i = 0;
  26.         this.j = 0;            
  27.     }
  28.    
  29.     public byte[] parse(final byte[] b) {
  30.         int k;
  31.         byte[] y = new byte[b.length];
  32.        
  33.         int position = 0;
  34.        
  35.         for(int a = 0; a < b.length; a++) {
  36.            this.i = ((this.i + 1) % 0x0100);
  37.            this.j = ((this.j + this.Table[this.i]) % 0x0100);
  38.            this.mk(this.i, this.j);
  39.            k = ((this.Table[this.i] + this.j) %  0x0100);
  40.            y[position++] = ((byte)(this.Table[k] ^ b[a]));
  41.         }
  42.         return y;
  43.     }
  44.    
  45.     private void mk (final int k, final int y) {
  46.         int x = this.Table[k];
  47.         this.Table[k] = this.Table[y];
  48.         this.Table[y] = x;
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement