forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrypt.cs
More file actions
160 lines (133 loc) · 4.66 KB
/
Copy pathCrypt.cs
File metadata and controls
160 lines (133 loc) · 4.66 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
namespace L2dotNET.Utility
{
class Crypt
{
private readonly byte[] _key = new byte[16]; //8];
private bool _enabled;
public void SetKey(byte[] key)
{
_key[0] = key[0];
_key[1] = key[1];
_key[2] = key[2];
_key[3] = key[3];
_key[4] = key[4];
_key[5] = key[5];
_key[6] = key[6];
_key[7] = key[7];
_key[8] = key[8];
_key[9] = key[9];
_key[10] = key[10];
_key[11] = key[11];
_key[12] = key[12];
_key[13] = key[13];
_key[14] = key[14];
_key[15] = key[15];
_enabled = true;
}
public void Decrypt(byte[] raw)
{
if (!_enabled)
return;
int temp = 0;
for (int i = 0; i < raw.Length; i++)
{
int temp2 = raw[i] & 0xff;
raw[i] = (byte)(temp2 ^ _key[i & 15] ^ temp);
temp = temp2;
}
long old = _key[8] & 0xff; //0
old |= (_key[9] << 8) & 0xff00; //1
old |= (_key[10] << 0x10) & 0xff0000; //2
old |= (_key[11] << 0x18) & 0xff000000; //3
old += raw.Length;
_key[8] = (byte)(old & 0xff); //0
_key[9] = (byte)((old >> 0x08) & 0xff); //1
_key[10] = (byte)((old >> 0x10) & 0xff); //2
_key[11] = (byte)((old >> 0x18) & 0xff); //3
}
public void Decrypt(byte[] raw, int offset, int size)
{
if (!_enabled)
return;
int temp = 0;
for (int i = 0; i < size; i++)
{
int temp2 = raw[offset + i] & 0xFF;
raw[offset + i] = (byte)(temp2 ^ _key[i & 15] ^ temp);
temp = temp2;
}
long old = _key[8] & 0xff;
old |= (_key[9] << 8) & 0xff00;
old |= (_key[10] << 0x10) & 0xff0000;
old |= (_key[11] << 0x18) & 0xff000000;
old += size;
_key[8] = (byte)(old & 0xff);
_key[9] = (byte)((old >> 0x08) & 0xff);
_key[10] = (byte)((old >> 0x10) & 0xff);
_key[11] = (byte)((old >> 0x18) & 0xff);
}
public void Decrypt(byte[] raw, int size)
{
if (!_enabled)
return;
uint temp = 0;
for (uint i = 0; i < size; i++)
{
uint temp2 = raw[i] & (uint)0xff;
raw[i] = (byte)(temp2 ^ _key[i & 15] ^ temp);
temp = temp2;
}
uint old = _key[8] & (uint)0xff; //0
old |= ((uint)_key[9] << 8) & 0xff00; //1
old |= ((uint)_key[10] << 0x10) & 0xff0000; //2
old |= ((uint)_key[11] << 0x18) & 0xff000000; //3
old += (uint)size;
_key[8] = (byte)(old & 0xff); //0
_key[9] = (byte)((old >> 0x08) & 0xff); //1
_key[10] = (byte)((old >> 0x10) & 0xff); //2
_key[11] = (byte)((old >> 0x18) & 0xff); //3
}
public void Encrypt(byte[] raw)
{
if (!_enabled)
return;
uint temp = 0;
for (int i = 0; i < raw.Length; i++)
{
uint temp2 = raw[i] & (uint)0xff;
temp = temp2 ^ _key[i & 15] ^ temp;
raw[i] = (byte)temp;
}
uint old = _key[8] & (uint)0xff;
old |= ((uint)_key[9] << 8) & 0xff00;
old |= ((uint)_key[10] << 0x10) & 0xff0000;
old |= ((uint)_key[11] << 0x18) & 0xff000000;
old += (uint)raw.Length;
_key[8] = (byte)(old & 0xff);
_key[9] = (byte)((old >> 0x08) & 0xff);
_key[10] = (byte)((old >> 0x10) & 0xff);
_key[11] = (byte)((old >> 0x18) & 0xff);
}
public void Encrypt(byte[] raw, uint size)
{
if (!_enabled)
return;
uint temp = 0;
for (uint i = 0; i < size; i++)
{
uint temp2 = raw[i] & (uint)0xff;
temp = temp2 ^ _key[i & 15] ^ temp;
raw[i] = (byte)temp;
}
uint old = _key[8] & (uint)0xff;
old |= ((uint)_key[9] << 8) & 0xff00;
old |= ((uint)_key[10] << 0x10) & 0xff0000;
old |= ((uint)_key[11] << 0x18) & 0xff000000;
old += size;
_key[8] = (byte)(old & 0xff);
_key[9] = (byte)((old >> 0x08) & 0xff);
_key[10] = (byte)((old >> 0x10) & 0xff);
_key[11] = (byte)((old >> 0x18) & 0xff);
}
}
}