Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Security/RC4.cpp

Go to the documentation of this file.
00001 #include "RC4.h"
00002 
00003 namespace crypt {
00004 
00005   void rc4_removeWarningAndDoNothingFunction() {
00006     if (RC4_magicbyte == RC4_magicbyte)
00007       if (RC4_key == RC4_key) {
00008 
00009       }
00010   }
00011 
00012   void rc4_init(struct rc4_state *s, unsigned char *key, int length)
00013   {
00014     int j=0, k=0;
00015 
00016     int *m = s->m;
00017     s->x = 0;
00018     s->y = 0;
00019 
00020     for (int i=0; i<256; i++)
00021       m[i] = i;
00022 
00023     for (int i=0; i<256; i++) {
00024       int a = m[i];
00025       j = (unsigned char)(j+a+key[k]);
00026       m[i] = m[j];
00027       m[j] = a;
00028 
00029       if (++k >= length)
00030         k = 0;
00031     }
00032   }
00033 
00034 
00035   void rc4_crypt(struct rc4_state *s, unsigned char *data, int length)
00036   {
00037     int  x = s->x;
00038     int  y = s->y;
00039     int *m = s->m;
00040 
00041     for (int i = 0; i < length; i++ ) {
00042       x = (unsigned char)(x+1);
00043       int a = m[x];
00044       y = (unsigned char)(y+a);
00045       int b = m[y];
00046       m[x] = b;
00047       m[y] = a;
00048       data[i] ^= m[(unsigned char)(a+b)];
00049     }
00050 
00051     s->x = x;
00052     s->y = y;
00053   }
00054 }

Generated on Mon Mar 20 22:00:09 2006 for GT2005 by doxygen 1.3.6