Menu

[r40]: / trunk / WhatsappClient / WhatsAppProtocol / Helper Classes / RC4.cs  Maximize  Restore  History

Download this file

53 lines (47 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
internal class RC4
{
private int i = 0;
private int j = 0;
private int[] s;
public RC4(byte[] key, int drop)
{
s = new int[256];
while (this.i < this.s.Length)
{
this.s[this.i] = this.i;
this.i++;
}
this.j = 0;
this.i = 0;
while (this.i < 0x100)
{
this.j = ((this.j + key[this.i % key.Length]) + this.s[this.i]) & 0xff;
Swap<int>(this.s, this.i, this.j);
this.i++;
}
this.i = this.j = 0;
this.Cipher(new byte[drop]);
}
public void Cipher(byte[] data)
{
this.Cipher(data, 0, data.Length);
}
public void Cipher(byte[] data, int offset, int length)
{
for (int i = length; i > 0; i--)
{
this.i = (this.i + 1) & 0xff;
this.j = (this.j + this.s[this.i]) & 0xff;
Swap<int>(this.s, this.i, this.j);
int index = offset++;
data[index] = (byte)(data[index] ^ this.s[(this.s[this.i] + this.s[this.j]) & 0xff]);
}
}
private static void Swap<T>(T[] s, int i, int j)
{
T num = s[i];
s[i] = s[j];
s[j] = num;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.