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
| #include<iostream> #include<stdlib.h> #include<Windows.h> #include<string.h> BYTE S[256] = {};
void decTEA(unsigned* target, unsigned* key) { unsigned int sum = 0; unsigned int v5; unsigned int v6;
for (int i = 0; i < 16; i += 2) { v6 = target[i]; v5 = target[i + 1]; sum = 0 - 0x61C88647 * 0x64; for (int j = 0; j < 0x64; ++j) { v5 -= (key[(sum >> 11) & 3] + sum) ^ (v6 + ((v6 >> 5) ^ (16 * v6))); sum += 0x61C88647; v6 -= (key[sum & 3] + sum) ^ (v5 + ((v5 >> 5) ^ (16 * v5)));
} target[i] = v6; target[i + 1] = v5; } }
void __cdecl swap(BYTE* a1, BYTE* a2) { char v2;
v2 = *a1; *a1 = *a2; *a2 = v2; } void __cdecl Sini(BYTE* a1, int len) { int k; int v3; int j; char v5[256]; int i;
for (i = 0; i < 256; ++i) S[i] = i; memset(v5, 0, sizeof(v5)); for (j = 0; j < 256; ++j) v5[j] = a1[j % len]; v3 = 0; for (k = 0; k < 256; ++k) { v3 = ((unsigned __int8)v5[k] + v3 + (unsigned __int8)S[k]) % 256; swap(&S[k], &S[v3]); } } void __cdecl decrc4(BYTE* target, int len, unsigned char* a3) { int i; int v6; int v7;
v7 = 0; v6 = 0; Sini(a3, 16); for (i = 0; i < len; ++i) { v7 = (v7 + 1) % 256; v6 = (v6 + (unsigned __int8)S[v7]) % 256; swap(&S[v7], &S[v6]); target[i] ^= S[((unsigned __int8)S[v6] + (unsigned __int8)S[v7]) % 256]; } }
int main(void) { unsigned char last[64] = { 0x59, 0x1B, 0xFD, 0xB4, 0x6B, 0xB8, 0xBE, 0xD9, 0xB3, 0xD3, 0x77, 0xD6, 0xF0, 0x65, 0x5F, 0x18, 0xA0, 0x9D, 0x3A, 0x53, 0x6D, 0x4A, 0x7B, 0x26, 0x74, 0x3A, 0x9C, 0x4E, 0x20, 0x43, 0x19, 0xD8, 0x72, 0xED, 0x95, 0xB5, 0x9C, 0x05, 0x22, 0x56, 0xCB, 0x7A, 0x11, 0x91, 0x9F, 0x7A, 0xBC, 0x0C, 0x4A, 0x69, 0x6D, 0xCE, 0x3D, 0xB4, 0xAB, 0x29, 0x61, 0xFA, 0x62, 0x32, 0xB4, 0xEC, 0x4C, 0xB6 }; unsigned int key[4] = { 0x0CAA5BDD, 0xD6846924, 0x51041EB8, 0x8B2AAB06 }; decTEA((unsigned*)last, key); unsigned char ikey[16] = { 0x76, 0x89, 0x33, 0x49, 0x19, 0x13, 0xC3, 0xC7, 0xAD, 0xD8, 0xE4, 0x68, 0xFC, 0x48, 0x04, 0xBC }; decrc4(last, 64, ikey); for (int i = 0; i < 64; i++) { std::cout << (unsigned char)last[i]; } }
|