#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<map> #include<vector> #include<queue> #include<stack> #include<set> #include<string> #include<cstring> #include<list> #include<stdlib.h> using namespace std; typedef int status; typedef int selemtype;
  unsigned char ida_chars[] = { 	0xD4, 0x16, 0x87, 0xD6, 0x54, 0x68, 0xBC, 0x02, 0x15, 0x6D,  	0x30, 0x08, 0x4B, 0x61, 0x4C, 0x5E, 0x42, 0xFD, 0x55, 0x61, 	0xB9, 0x27, 0x6F, 0xF5, 0xB6, 0x86, 0x23, 0xA9, 0xEF, 0x1C, 	0x04, 0x9F }; typedef unsigned longULONG;  
  void rc4_init(unsigned char*s, unsigned char*key, unsigned long Len) {     int i = 0, j = 0;     char k[256] = { 0 };     unsigned char tmp = 0;     for (i = 0; i<256; i++)     {         s[i] = i;         k[i] = key[i%Len];     }     for (i = 0; i<256; i++)     {         j = (j + s[i] + k[i]) % 256;         tmp = s[i];         s[i] = s[j];         s[j] = tmp;     } }  
  void rc4_crypt(unsigned char*s, unsigned char*Data, unsigned long Len) {     int i = 0, j = 0, t = 0;     unsigned long k = 0;     unsigned char tmp;     for (k = 0; k<Len; k++)     {         i = (i + 1) % 256;         j = (j + s[i]) % 256;         tmp = s[i];         s[i] = s[j];         s[j] = tmp;         t = (s[i] + s[j]) % 256;         Data[k] ^= s[t];     } }   int main() {     unsigned char s[256] = { 0 }, s2[256] = { 0 };     char key[256] = { "you_are_master" };    unsigned char pData[512] = { 		0xf,0x94,0xae,0xf2,0xc0,0x57,0xc2,0xe0,0x9a,0x45, 		0x37,0x50,0xf5,0xa0,0x5e,0xcb,0x2c,0x16,0x28,0x29, 		0xfe,0xff,0x33,0x46,0xe,0x57,0x82,0x22,0x52,0x26, 		0x2b,0x6e,0xe4,0x82,0x24 	};     unsigned long len = 35;     int i;       printf("pData=%s\n", pData);     printf("key=%s,length=%d\n\n", key, strlen(key));     rc4_init(s, (unsigned char*)key, strlen(key));     printf("完成对S[i]的初始化,如下:\n\n");     for (i = 0; i<256; i++)     {         printf("%02X", s[i]);         if (i && (i + 1) % 16 == 0)putchar('\n');     }     printf("\n\n");     for (i = 0; i<256; i++)     {         s2[i] = s[i];     }
      rc4_crypt(s, (unsigned char*)pData, len);
      printf("现在解密:\n\n");               printf("pData=%s\n\n", pData);     return 0; }
 
   |