RC4 – to Problem Session 20.12.2004 Let’s consider initialization of RC4 algorithm. We assume that length w=8 (number of elements in permutation) instead of 256, used in RC4 Initialization of S: For i=0,w-1{ S[i]=I; T[i]=K[I mod keylen]; } where T – auxiliary array, K – array of key values, keylen – number of values in array K. Let keylen=4 and K is 5 4 2 1 Then, after initialization: S is 0 1 2 3 4 5 6 7 And T is: 5 4 2 1 5 4 2 1 Initial permutation is obtained by J=0; For i=0,w-1{ J=(j+s[i]+T[i]) mod w; Swap(s[i],s[j]); } Respectively, we get I=0,j=0+0+5=5: 5 1 2 3 4 0 6 7 I=1,j=(5+1+4)mod8=2: 5 2 1 3 4 0 6 7 I=2,j=2+1+2=5: 5 2 0 3 4 1 6 7 I=3,j=(5+3+1)modw=1 5 3 0 2 4 1 6 7 I=4,j=(1+4+5)mod8=2 5 3 4 2 0 1 6 7 I=5,j=2+1+4=7 5 3 4 2 0 7 6 1 I=6,j=(7+6+2)modw=7 5 3 4 2 0 7 1 6 I=7,j=(7+6+1)mod8=6 5 3 4 2 0 7 6 1 So, initial permutation S is 5 3 4 2 0 7 6 1 and it is used for generation of pseudo-random stream of numbers with the help of the following code: I=j=0; While(true){ I=(i+1) mod w; J=(j+s[i]) mod w; Swap(s[i],s[j]); Index=(s[i]+s[j]) mod w; //place of element to be output Output=s[index]; //value of output element } where Output denotes next value in the generated stream.