当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

 ·[随笔]今夜无眠。。。。。。    »显示摘要«
    摘要: 爱,究竟是一种什么东西?这也许正是感情最令人难以琢磨,难以把握的原因!女孩喜欢男孩细心、浪漫、懂得体贴人,男孩喜欢女孩温柔、漂亮、有女人味!对,也许女人味正是我一直苦苦追寻的感觉!换句话说喜欢是什么东西呢?感觉?但感觉这东西是否真的消失了不会再回来?那么今晚的相见又代表什么呢?是的,我一直在思考一个答案,但是仔细想想得到答案后自己又会怎样?说实话,今晚的相见、今晚的聊天让我感到意外,也没想......
 ·请介绍国外热门论坛    »显示摘要«
    摘要: 如这个csdn,类似的热门论坛。 专门的也行, 最好是综合性的,什么内容都有。 我想看看老外在干些什么! ......


求RC4的算法原代码

那位大侠有RC4的算法原代码?  
  急用,QQ:52943597     EMAIL:zhiyuan_li@tom.com

NO.1   作者: tigerhohoo

rc4.h      
  #ifndef   _RC4_H  
  #define   _RC4_H  
   
  struct   rc4_state  
  {  
          int   x,   y,   m[256];  
  };  
   
  void   rc4_setup(   struct   rc4_state   *s,   unsigned   char   *key,     int   length   );  
  void   rc4_crypt(   struct   rc4_state   *s,   unsigned   char   *data,   int   length   );  
   
  #endif   /*   rc4.h   */  
   
     
  rc4.c      
  /*  
    *   An   implementation   of   the   ARC4   algorithm,  
    *   by   Christophe   Devine   <devine@cr0.net>;  
    *   this   program   is   licensed   under   the   GPL.  
    */  
   
  #include   "rc4.h"  
   
  void   rc4_setup(   struct   rc4_state   *s,   unsigned   char   *key,     int   length   )  
  {  
          int   i,   j,   k,   *m,   a;  
   
          s->x   =   0;  
          s->y   =   0;  
          m   =   s->m;  
   
          for(   i   =   0;   i   <   256;   i++   )  
          {  
                  m[i]   =   i;  
          }  
   
          j   =   k   =   0;  
   
          for(   i   =   0;   i   <   256;   i++   )  
          {  
                  a   =   m[i];  
                  j   =   (unsigned   char)   (   j   +   a   +   key[k]   );  
                  m[i]   =   m[j];   m[j]   =   a;  
                  if(   ++k   >=   length   )   k   =   0;  
          }  
  }  
   
  void   rc4_crypt(   struct   rc4_state   *s,   unsigned   char   *data,   int   length   )  
  {    
          int   i,   x,   y,   *m,   a,   b;  
   
          x   =   s->x;  
          y   =   s->y;  
          m   =   s->m;  
   
          for(   i   =   0;   i   <   length;   i++   )  
          {  
                  x   =   (unsigned   char)   (   x   +   1   );   a   =   m[x];  
                  y   =   (unsigned   char)   (   y   +   a   );  
                  m[x]   =   b   =   m[y];  
                  m[y]   =   a;  
                  data[i]   ^=   m[(unsigned   char)   (   a   +   b   )];  
          }  
   
          s->x   =   x;  
          s->y   =   y;  
  }  
   
  #ifdef   TEST  
   
  #include   <string.h>  
  #include   <stdio.h>  
   
  /*  
    *   the   following   tests   come   from   the   OpenSSL   test   suite  
    *   (crypto/rc4/rc4test.c)  
    */  
   
  static   unsigned   char   keys[7][30]={  
                  {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},  
                  {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},  
                  {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},  
                  {4,0xef,0x01,0x23,0x45},  
                  {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},  
                  {4,0xef,0x01,0x23,0x45},  
                  };  
   
  static   unsigned   char   data_len[7]={8,8,8,20,28,10};  
  static   unsigned   char   data[7][30]={  
                  {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff},  
                  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},  
                  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},  
                  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
                        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  
                        0x00,0x00,0x00,0x00,0xff},  
                  {0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,  
                        0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,  
                        0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,  
                        0x12,0x34,0x56,0x78,0xff},  
                  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},  
                  {0},  
                  };  
   
  static   unsigned   char   output[7][30]={  
                  {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00},  
                  {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00},  
                  {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00},  
                  {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,  
                    0xbd,0x61,0x5a,0x11,0x62,0xe1,0xc7,0xba,  
                    0x36,0xb6,0x78,0x58,0x00},  
                  {0x66,0xa0,0x94,0x9f,0x8a,0xf7,0xd6,0x89,  
                    0x1f,0x7f,0x83,0x2b,0xa8,0x33,0xc0,0x0c,  
                    0x89,0x2e,0xbe,0x30,0x14,0x3c,0xe2,0x87,  
                    0x40,0x01,0x1e,0xcf,0x00},  
                  {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61,0x00},  
                  {0},  
                  };  
   
  int   main(   void   )  
  {  
          int   i;  
          struct   rc4_state   s;  
          unsigned   char   buffer[30];  
   
          for(   i   =   0;   i   <   7;   i++   )  
          {  
                  rc4_setup(   &s,   &keys[i][1],   keys[i][0]   );  
                  memcpy(   buffer,   data[i],   data_len[i]   );  
                  rc4_crypt(   &s,   buffer,   data_len[i]   );  
   
                  printf(   "test   %d   ",   i   +   1   );  
   
                  if(   !   memcmp(   buffer,   output[i],   data_len[i]   )   )  
                  {  
                          printf(   "passed\n"   );  
                  }  
                  else  
                  {  
                          printf(   "failed\n"   );  
                          return(   1   );  
                  }  
          }  
   
          return(   0   );  
  }  
   
  #endif  
   
     
 


    摘要: 求助 金山毒霸序列号试完就给分 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE