Advertisement
Nasty

HabboRC4 [CappoJava]

Apr 6th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package Server.Crypto;
  2.  
  3. /*
  4.  *****************
  5.  * @author capos *
  6.  *****************
  7. */
  8.  
  9. public class HabboRC4
  10. {
  11.     private int i = 0;
  12.     private int j = 0;
  13.     private int[] Table = new int[256];
  14.            
  15.     public void init(byte[] a)
  16.     {
  17.         int k = a.length;
  18.         this.i = 0;
  19.         while (this.i < 256)
  20.         {
  21.             this.Table[this.i] = this.i;
  22.             this.i++;
  23.         }
  24.         this.j = 0;
  25.         this.i = 0;
  26.         while (this.i < 256)
  27.         {
  28.             this.j = ((this.j + this.Table[this.i]) + (a[this.i % k] & 0xff)) % 256;
  29.             this.Swamp(this.i, this.j);
  30.             this.i++;
  31.         }
  32.         this.i = 0;
  33.         this.j = 0;
  34.     }
  35.    
  36.     public void parse(byte[] b) // encrypt and decrypt
  37.     {
  38.         for(int a = 0;a<b.length;a++)
  39.         {
  40.             this.i = (this.i + 1) % 256;
  41.             this.j = (this.j + this.Table[this.i]) % 256;
  42.             this.Swamp(this.i, this.j);
  43.             b[a] = (byte) ((b[a] & 0xff) ^ this.Table[(this.Table[this.i] + this.Table[this.j]) % 256]);
  44.         }
  45.     }
  46.    
  47.     private void Swamp(int a1, int a2)
  48.     {
  49.         int k = this.Table[a1];
  50.         this.Table[a1] = this.Table[a2];
  51.         this.Table[a2] = k;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement