RC4 is a byte-oriented stream cipher: it expands a secret key into a keystream, then XORs each keystream byte with plaintext to produce ciphertext. Its appeal was simple software and hardware implementation, but its use in WEP made Wi-Fi preshared keys recoverable from captured traffic under particular conditions. section 4.3 section 4.4
The cipher keeps a 256-byte S-box containing a permutation of 0 through 255, plus moving indices i and j. Initialization fills the S-box with its indices; later swaps preserve every byte while changing their positions. The state can be pictured as a box of numbered rocks: shaking changes the order, not the collection. section 4.3.1
Figure 4.10 RC4 internal state: a 256-byte S-box and two pointers, i and j
Inspect the two pieces of mutable RC4 state: the 256-byte permutation and the indices that traverse it. section 4.3.1
RC4 runs in two phases:
- Key-scheduling algorithm (KSA): initialize S[0..255], then for each index update j with the current state byte and a repeating key byte, and swap S[i] with S[j]. KSA runs once for a new key. section 4.3.1
- Pseudo-random generation algorithm (PRGA): repeatedly advance i, update j from S[i], swap the selected entries, and select one S-box byte as output. Each output byte joins the keystream. section 4.3.1
- Encryption: run KSA, generate as many keystream bytes as the plaintext requires, and XOR corresponding bytes. The same keystream relationship makes known plaintext useful to an attacker. section 4.3.1 section 4.1.2
WEP and the FMS attack
WEP formed each packet’s RC4 key by concatenating a public three-byte initialization vector (IV) with a shared Wi-Fi password. For weak IV patterns, RC4’s key scheduling produces statistical biases. An attacker who captures many such encrypted packets can XOR a known packet header with ciphertext to obtain a keystream byte, simulate the relevant KSA steps using already guessed key bytes, vote on the next password byte, and repeat. A Go demonstration recovers test keys with 50,000 messages, while 500 messages can produce wrong byte guesses. section 4.3.2 section 4.3.2
The failure is not merely reuse of one visible packet key: WEP intended each public IV to create a different RC4 key. Instead, weak-IV bias leaks information about the appended preshared key across enough observations. Discarding an initial portion of RC4 output is described as a mitigation for problematic early-byte indices, but the demonstrated WEP construction remains an insecure deployment. section 4.3.2 section 10.1.2

