Graphics Programs Reference
In-Depth Information
Again, the correct key byte is determined. Of course, for the sake of
demonstration, values for X have been strategically picked. To give you a
true sense of the statistical nature of the attack against a full RC4 imple-
mentation, the following source code has been included:
fms.c
#include <stdio.h>
/* RC4 stream cipher */
int RC4(int *IV, int *key) {
int K[256];
int S[256];
int seed[16];
int i, j, k, t;
//Seed = IV + key;
for(k=0; k<3; k++)
seed[k] = IV[k];
for(k=0; k<13; k++)
seed[k+3] = key[k];
// -= Key Scheduling Algorithm (KSA) =-
//Initialize the arrays.
for(k=0; k<256; k++) {
S[k] = k;
K[k] = seed[k%16];
}
j=0;
for(i=0; i < 256; i++) {
j = (j + S[i] + K[i])%256;
t=S[i]; S[i]=S[j]; S[j]=t; // Swap(S[i], S[j]);
}
// First step of PRGA for first keystream byte
i = 0;
j = 0;
i = i + 1;
j = j + S[i];
t=S[i]; S[i]=S[j]; S[j]=t; // Swap(S[i], S[j]);
k = (S[i] + S[j])%256;
return S[k];
}
int main(int argc, char *argv[]) {
int K[256];
int S[256];
int IV[3];
Search WWH ::




Custom Search