RC4
1. What Is RC4? (beginner — simplest stream cipher!)
RC4 (Ron Rivest, 1987) = byte-at-a-time stream cipher: secret state (256-byte permutation + pointers ) spits keystream bytes, XOR with plaintext! Variable key 40-2048 bits. Tiny code, very fast — but BIASED (retired!).
KSA (key setup — scramble S with key!):
S[i] = i for 0..255; j = 0
for i = 0..255: j = (j + S[i] + key[i mod keylen]) mod 256; swap(S[i], S[j])
PRGA (spit bytes — key no longer used!):
i = 0; j = 0
loop: i = (i+1) mod 256; j = (j + S[i]) mod 256
swap(S[i], S[j]); t = (S[i] + S[j]) mod 256; output S[t]
ENCRYPT: ciphertext byte = plaintext byte XOR keystream byte (decrypt same!)
4. Why Retired? (exam viva — biases!)
- First bytes biased (Fluhrer-Mantin-Shamir: 2nd byte zero with double probability!) → WEP cracked (IV + key concat!).
- Discard first 3072 bytes helps, but TLS attacks (2013: sessions recover!) killed it. Use ChaCha20 / AES-CTR!
- Stream rule: NEVER reuse key (two-time pad! XOR = XOR !).
5. Exam Points
- KSA + PRGA pseudocode — 7 marks, very frequent.
- XOR encrypt/decrypt + biases/WEP — 5 marks, favourite.
- Never-reuse-key rule — 2-3 marks, evergreen trap.