The RC4 (Rivest Cipher 4) encryption algorithm is a symmetric key encryption algorithm that encrypts plain text in small chunks producing multiple
RC4 encryption algorithm comprises two components—KSA (Key scheduling algorithm) and PRGA (Pseudo random generation algorithm). These two algorithms together help the rc4 algorithm to produce the stream cipher.
Following are the procedures involved in RC4 encryption:
T
, is generated where the first (k - len
) elements of the key, K
, are copied into it as shown below:char S[256];
for(int i=0;i<256;i++){
S[i] = i;
T[i] = K[i mod (k - len)]
}
The main purpose of creating a temporary array is to provide an initial permutation for the S array.
S
. KSA will use the secret key and the temporary array T
to set the values of the S
array's entries as follows:int i, j=0;
while(i<256){
j= (j + S[i] + T[i])mod 256; // T is the temporary vector created from the secret key.
int temp = 0;
temp = S[i]; //swap S[i] and S[j]
S[i] = S[j];
S[j] = temp;
i++;
}
In the above code, the values in the S
array are swapped with the i
and j
indexes produced. At this point, the array S
is completely initialized to be used in PRGA as input.
S
modified by the KSA algorithm. The code for PRGA is as follows:int i, j =0;
while(1){
i = ( i + 1 ) mod 256;
j = ( j + S[i] ) mod 256;
int temp = 0;
temp = S[i]; //swap S[i] and S[j]
S[i] = S[j];
S[j] = temp;
t = ( S[i] + S[j] ) mod 256 ;
k = S[t]; // k is the byte generated from S by scrambling entries in a calculated way
}
RC4 encryption algorithms are easy to use, do not require an exuberant amount of memory to operate, and are implemented on large data streams. However, RC4 encryption does not provide authentication, which can compromise security.
Free Resources