I've looked up RC4 algorithm and it's seems easy enough but some parts of it seem random to me. In the key schedule part take for example the following part :
j = (j + S[i] + key[i % keylen]) % 256
I can understand most of it:
- the
key[i % keylen]
is padding in-case that the key is shorter than 256 bytes, and - the
% 256
is to ensure thatj
will be in the range of 0-255 when performing the swap.
But why do we need the j = j + S[i]
?
Is there a mathematical explanation to this or is it just to add some randomness? Also regarding to the pseudo random generator part: can someone point me to a reference which offers an explanation for the not so obvious operations?
I've looked for explanations on the internet but couldn't really find anywhere that explain those bits.