RC4 Example
RC4 Example
Initialise the state vector S and temporary vector T. S is initialised so the S[i] = i, and T is
initialised so it is the key K (repeated as necessary).
S = [0 1 2 3 4 5 6 7]
T = [1 2 3 6 1 2 3 6]
For i = 0:
j = (0 + 0 + 1) mod 8
= 1
Swap(S[0],S[1]);
S = [1 0 2 3 4 5 6 7]
For i = 1:
j=3
Swap(S[1],S[3])
S = [1 3 2 0 4 5 6 7];
For i = 2:
j=0
Swap(S[2],S[0]);
S = [2 3 1 0 4 5 6 7];
For i = 3:
j = 6;
Swap(S[3],S[6])
S = [2 3 1 6 4 5 0 7];
Simplified RC4 1
For i = 4:
j=3
Swap(S[4],S[3])
S = [2 3 1 4 6 5 0 7];
For i = 5:
j=2
Swap(S[5],S[2]);
S = [2 3 5 4 6 1 0 7];
For i = 6:
j = 5;
Swap(S[6],S[4])
S = [2 3 5 4 0 1 6 7];
For i = 7:
j = 2;
Swap(S[7],S[2])
S = [2 3 7 4 0 1 6 5];
Now we generate 3-bits at a time, k, that we XOR with each 3-bits of plaintext to produce the
ciphertext. The 3-bits k is generated by:
i, j = 0;
while (true) {
i = (i + 1) mod 8;
j = (j + S[i]) mod 8;
Swap (S[i], S[j]);
t = (S[i] + S[j]) mod 8;
k = S[t]; }
Remember, P = [1 2 2 2]
So to encrypt the plaintext stream P = [1 2 2 2] with key K = [1 2 3 6] using our simplified RC4
stream cipher we get C = [4 1 2 0].
Simplified RC4 3