Finish your 3-bit example, then scale up
Initialize S = [0,1,…,n−1]. Repeat key into T. Swap S[i] with S[j] where:
j = (j + S[i] + T[i]) mod n
Real RC4: n=256. Your toy: n=8 (3-bit).
Generate keystream byte k, XOR with plaintext:
i = (i + 1) mod n j = (j + S[i]) mod n swap S[i], S[j] t = (S[i] + S[j]) mod n k = S[t] C = P ⊕ k
K = [3,5,2], P = [6,1,4]. Steps computed live (Stallings RC4: KSA then PRGA).
Scale to mod 16. S = [0,1,…,15]. K = [3,5,2,7]. P = [9,4,12,7,1]. Steps below are computed live — change inputs to practice.
After KSA finishes, what operation produces the ciphertext?