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
|
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#define MX (((z >> 5) ^ (y << 2)) + ((y >> 3) ^ (z << 4))) ^ ((sum ^ y) + (key[(p & 3) ^ e] ^ z))
#define DELTA 0x9e3779b9
static DWORD* xxtea_uint_encrypt(DWORD* data, size_t len, DWORD* key) {
DWORD n = (DWORD)len - 1;
DWORD z = data[n], y, p, q = 6 + 52 / (n + 1), sum = 0, e;
if (n < 1) return data;
while (0 < q--) {
sum += DELTA;
e = sum >> 2 & 3;
for (p = 0; p < n; p++) {
y = data[p + 1];
z = data[p] += MX;
}
y = data[0];
z = data[n] += MX;
}
return data;
}
static DWORD* xxtea_uint_decrypt(DWORD* data, size_t len, DWORD* key) {
DWORD n = (DWORD)len - 1;
DWORD z, y = data[0], p, q = 6 + 52 / (n + 1), sum = q * DELTA, e;
if (n < 1) return data;
while (sum != 0) {
e = sum >> 2 & 3;
for (p = n; p > 0; p--) {
z = data[p - 1];
y = data[p] -= MX;
}
z = data[n];
y = data[0] -= MX;
sum -= DELTA;
}
return data;
}
int main(){
BYTE data[] =
{
0x23, 0xB3, 0x4E, 0xE7, 0x36, 0x28, 0xA7, 0xB7, 0xE2, 0x6F,
0xCA, 0x59, 0xC1, 0xC5, 0x7C, 0x96, 0x74, 0x26, 0x80, 0xE7,
0xE6, 0x54, 0x2D, 0x3D, 0x56, 0x03, 0x9D, 0x8A, 0x9C, 0xC3,
0xDC, 0x99, 0xED, 0xD8, 0x26, 0x70, 0xAD, 0xFD, 0x33, 0x6A,
0x0A, 0x55, 0x96, 0xF4, 0x9E, 0x6F, 0x9C, 0x5C, 0x4C, 0xD0,
0xE5, 0x1B, 0x17, 0xAE, 0x23, 0x67, 0xC2, 0xA5, 0x70, 0x52,
0x0A, 0x13, 0x42, 0xAC, 0xB2, 0x67, 0xBE, 0x84, 0x79, 0xC7,
0x5C, 0x70, 0x98, 0x3D, 0x51, 0x5C, 0x2D, 0xDA, 0x36, 0xFB,
0x45, 0x96, 0x17, 0x22, 0x9D, 0x52, 0xE3, 0x5C, 0xFB, 0xE1,
0x89, 0xD1, 0x89, 0xD4, 0x5B, 0xE8, 0x1F, 0xD1, 0xC8, 0x73,
0x96, 0xC1, 0xB5, 0x54, 0x90, 0xB4, 0x7C, 0xB6, 0xCA, 0xE4,
0x17, 0x21, 0x94, 0xF9, 0xE3, 0x9D, 0xAA, 0xA1, 0x5A, 0x2F,
0xFD, 0x01, 0xE8, 0xA7, 0xAB, 0x6E, 0x0D, 0xC3, 0x9C, 0xDC,
0xAD, 0x1B, 0x4A, 0xB0, 0x53, 0x34, 0xF9, 0x06, 0xA4, 0x92
};
int key[] = { 1,2,3,4 };
DWORD * x = xxtea_uint_decrypt((DWORD*)data, 35, (DWORD*)key);
for (int i = 0; i < 35; i++) {
printf("%c", x[i]);
}
return 0;
}
|