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
| #include <stdio.h>
struct rc4 { int x, y, m[256]; };
typedef unsigned char uint8;
int main() { uint8 flag[100] = { 0 }; uint8 cmp[] = { 0x12,0xa7,0xf5,0xde,0x75,0x2a,0x6e,0x4a,0x6e,0x73,0xe6,0x62,0x50,0xbf,0x2a,0x98,0xfe,0x2b,0xdd,0x7b,0xba,0xb6,0x5,0x13,0x63,0x57,0x2d,0xd4,0x45,0xb8,0xfe,0xbc }; uint8 key[8] = { 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF }; int i, j, k, a,b; struct rc4 s; int length = 8; memset(&s, 0, sizeof(s)); s.x = 0; s.y = 0; for (i = 0; i < 256; i++) s.m[i] = i; j = k = 0; for (i = 0; i < 256; i++) { a = s.m[i]; j = (uint8)(j + a + key[k]); s.m[i] = s.m[j]; s.m[j] = a; if (++k >= length) k = 0; }
length = 32; for (i = 0; i < length; i++) { s.x = (uint8)(s.x + 1); a = s.m[s.x]; s.y = (uint8)(s.y + a); s.m[s.x] = b = s.m[s.y]; s.m[s.y] = a; flag[i] = cmp[i] ^ s.m[(uint8)(a + b)]; } printf("flag{%s}", flag); }
|