The code implements rc4 encryption over the file. RC4 is a variable-key-size
stream cypher developed in 1987 by RSA Data Security. The algorythm is immune
to differential and linear cryptoanalysis, doesn't seem to have any small
cycles and is highly nonlinear.

The basic idea of the algorytm follows:
The keystream here is independent from the plain text. it has 8 * 8 S-box 
(S[0]...S[255]). The entries are permutation of the numbers 0 through 255, and
the permutation is a function of the variable-length key. it has two counters,
i and j both initialized to zero. To generate random byte do the following:

i=(i+1) % 256;
j=(j+S[i]) % 256;
swap_byte(S[i],S[j]);
t=(S[i]+S[j] % 256);
K=S[t];

The random byte K is XORed with the plaintext byte to produce ciphertext byte,
or XORed with the ciphertext byte to produce plaintext. 

(the code implementation is following: suppose K[] is key with length of KLEN;
then we create 2 arrays KEY[256] and STATE[256]; STATE is being filled in with
its indexes (STATE[0]=0; STATE[1]=1;...) while KEY[256] is being repeatedly
filled with the key K[]; then:
j=0;
for(i=0;i<256;i++) {
j=(j+STATE[i]+KEY[i]) % 256;
swap_byte(STATE[i],STATE[j]);
}

then STATE is being used to generate cyphertext. That's it.



by APPLIED CRYPTOGRAPHY (BRUCE SCHNEIER) materials.

~CyberPsychotic

Fri Oct  8 01:01:53 KGST 1999
