Guest User

Untitled

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