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
| #include <stdio.h> #include <string.h> #include<stdlib.h> void init(unsigned char* s, unsigned char* key) {
int i = 0; int j = 0; unsigned char k[256]; unsigned char temp = 0; for (i = 0; i < 256; i++) { s[i] = i; k[i] = key[i % strlen(key)]; } for (int l=0; l < 99999; l++) { j = 0; for (i = 0; i < 256; i++) { j = (j + s[i] + k[i]) % 256; temp = s[i]; s[i] = s[j]; s[j] = temp; } } } void crypt(unsigned char* s, unsigned char* data, unsigned long len) { int i = 0, j = 0, t = 0; unsigned long k = 0; unsigned char temp; for (k = 0; k < len; k++) { i = (i + 1) % 256; j = (j + s[i]) % 256; temp = s[i]; s[i] = s[j]; s[j] = temp; t = (s[i] + s[j]) % 256; data[k] ^= s[t]; } } int main() { unsigned char s[256] = { 0 }; char key[] = "InfinityLoop"; unsigned char data[] = { 0xA6, 0x3D, 0x54, 0xB0, 0x74, 0xCC, 0xBD, 0x2A, 0x4A, 0xDE, 0xBD, 0x35, 0xD1, 0x1D, 0x80, 0x32, 0x5F, 0x64, 0x2F, 0xC5, 0xDD, 0x11, 0x3E, 0x95, 0xCC, 0x17, 0x13, 0xE5, 0x5E, 0x65, 0xCE, 0x42, 0x9E, 0x47, 0xC8, 0xF3, 0x4D, 0x8A, 0xA6, 0x1F, 0xF0, 0x50, 0x27, 0xA2, 0x28, 0x81, 0x24, 0xA7, 0xB4, 0x90, 0xFC, 0x93, 0x8A, 0xC1, 0x77, 0xD5, 0x16, 0x1E, 0xFD, 0x87, 0xC7, 0xBB, 0xB3, 0x00 }; init(s, key); crypt(s, data, 63); for (int i = 0; i < 64; i++) { printf("%c", data[i]); } return 0; }
|