27static unsigned char RC4_Temp_Byte;
28#define RC4_SWAP_BYTE(a,b) RC4_Temp_Byte=a; a=b; b=RC4_Temp_Byte
33static unsigned char RC4_Table_Init[]={
54 100, 101, 102, 103, 104,
55 105, 106, 107, 108, 109,
56 110, 111, 112, 113, 114,
57 115, 116, 117, 118, 119,
58 120, 121, 122, 123, 124,
59 125, 126, 127, 128, 129,
60 130, 131, 132, 133, 134,
61 135, 136, 137, 138, 139,
62 140, 141, 142, 143, 144,
63 145, 146, 147, 148, 149,
64 150, 151, 152, 153, 154,
65 155, 156, 157, 158, 159,
66 160, 161, 162, 163, 164,
67 165, 166, 167, 168, 169,
68 170, 171, 172, 173, 174,
69 175, 176, 177, 178, 179,
70 180, 181, 182, 183, 184,
71 185, 186, 187, 188, 189,
72 190, 191, 192, 193, 194,
73 195, 196, 197, 198, 199,
74 200, 201, 202, 203, 204,
75 205, 206, 207, 208, 209,
76 210, 211, 212, 213, 214,
77 215, 216, 217, 218, 219,
78 220, 221, 222, 223, 224,
79 225, 226, 227, 228, 229,
80 230, 231, 232, 233, 234,
81 235, 236, 237, 238, 239,
82 240, 241, 242, 243, 244,
83 245, 246, 247, 248, 249,
84 250, 251, 252, 253, 254,
97 memset(Key.State, 0, 256);
109 switch(key_data_len) {
111 Prepare_Key_8bytes(key_data_ptr);
115 Prepare_Key_16bytes(key_data_ptr);
120 unsigned char index1;
121 unsigned char index2;
122 unsigned char *state;
125 state = &Key.State[0];
126 memcpy(state, RC4_Table_Init, 256);
133 index2 = (key_data_ptr[index1] + state[
counter] + index2);
135 index1 = (
unsigned char)((index1 + 1) % key_data_len);
143 unsigned char *state;
144 state = &Key.State[0];
145 for (
int i=0; i<256; i+=5) {
146 printf(
" %3d %3d %3d %3d %3d\n",state[i], state[i+1], state[i+2], state[i+3], state[i+4]);
148 printf(
"X = %d Y = %d\n\n",Key.X,Key.Y);
162 unsigned char *state;
163 unsigned char *buffer_end=buffer_ptr+buffer_len;
164 unsigned char *buffer_cur=buffer_ptr;
169 state = &Key.State[0];
170 while(buffer_cur != buffer_end) {
172 y = (
unsigned char)(y + state[x]);
174 *buffer_cur ^= state[(state[x] + state[y]) & 255];
194 memcpy(Key.State, other.Key.State, 256);
209void RC4Class::Prepare_Key_8bytes(
const unsigned char *key_data_ptr)
211 unsigned char index1;
212 unsigned char index2;
213 unsigned char *state;
216 state = &Key.State[0];
217 memcpy(state, RC4_Table_Init, 256);
224 index2 = (
unsigned char)(key_data_ptr[index1] + state[
counter] + index2);
237void RC4Class::Prepare_Key_16bytes(
const unsigned char *key_data_ptr)
239 unsigned char index1;
240 unsigned char index2;
241 unsigned char *state;
244 state = &Key.State[0];
245 memcpy(state, RC4_Table_Init, 256);
252 index2 = (
unsigned char)(key_data_ptr[index1] + state[
counter] + index2);
void Prepare_Key(const unsigned char *key_data_ptr, int key_data_len)
RC4Class & operator=(const RC4Class &other)
void RC4(unsigned char *buffer_ptr, int buffer_len)
#define RC4_SWAP_BYTE(a, b)