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
| #include <stdio.h> #include <stdlib.h> #include <string.h> unsigned char enc[] = { 0xF7, 0x5F, 0xE7, 0xB0, 0x9A, 0xB4, 0xE0, 0xE7, 0x9E, 0x05, 0xFE, 0xD8, 0x35, 0x5C, 0x72, 0xE0, 0x86, 0xDE, 0x73, 0x9F, 0x9A, 0xF6, 0x0D, 0xDC, 0xC8, 0x4F, 0xC2, 0xA4, 0x7A, 0xB5, 0xE3, 0xCD, 0x60, 0x9D, 0x04, 0x1F }; void rc4_init_s(unsigned char* s) { for (int i = 0; i < 256; i++) { s[i] = i; } }
void rc4_shuffle(unsigned char* s, unsigned char* key, int key_len) { int j = 0; for (int i = 0; i < 256; i++) { j = (j + s[i] + key[i % key_len]) % 256; int tmp = s[i]; s[i] = s[j]; s[j] = tmp; } }
void rc4_gen_keystream(unsigned char* s, int len, unsigned char* key_stream) { int i = 0, j = 0, cnt = -1; while (len) { i = (i + 1) % 256; j = (j + s[i]) % 256; int tmp = s[i]; s[i] = s[j]; s[j] = tmp; key_stream[++cnt] = s[(s[i] + s[j]) % 256]; len -= 1; } } int main() { unsigned char keystream1[50]; unsigned char keystream[50]; unsigned char xbox[256]; unsigned char key[] = { 0x7C, 0x4E, 0x1A, 0x48, 0x1B, 0x46, 0x18, 0x74, 0x5F, 0x1B, 0x74, 0x4F, 0x75, 0x18, 0x48, 0x5F, 0x4D }; for (int i = 0; i < 17; i++) { key[i] ^= 43; } rc4_init_s(xbox); rc4_shuffle(xbox,key, 17); rc4_gen_keystream(xbox, 36, keystream1); unsigned char primes[] = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 }; memcpy(key + 17, primes, 10); rc4_shuffle(xbox, key, 27); for (int i = 0; i < 17; i++) { rc4_gen_keystream(xbox, 36, keystream); } for (int i = 0; i < 36; i += 2) { for (unsigned char a1 = 0; a1 < 0xff; a1++) { for (unsigned char a2 = 0; a2 < 0xff; a2++) { unsigned char a10 = a1; unsigned char a20 = a2; a1 = a1 ^ keystream1[i]; a2 = a2 ^ keystream1[i + 1]; a1 = (a1 + a2) ^ keystream[i]; a2 = (a1 - a2) ^ keystream[i + 1]; if (a1 == enc[i] && a2 == enc[i + 1]) { printf("%c%c", a10, a20); } a1 = a10; a2 = a20; } } } return 0; }
|