liveBook · Manning

Pseudorandom generation algorithm

As explained in Hacking Cryptography

RC4's pseudorandom generation algorithm updates the cipher state and produces successive keystream bytes.

The RC4 pseudorandom generation algorithm (PRGA) turns the shuffled S-box into a keystream. After key scheduling initializes the permutation, PRGA repeatedly updates the cipher state and emits one byte at a time. section 4.3.1

Each PRGA iteration performs four state and output operations:

Go implementation

A length-limited implementation repeats the PRGA loop, stores each selected state byte in keyStream, and returns the resulting sequence. RC4 then XORs that sequence with plaintext to produce ciphertext. In WEP, the first keystream byte can be recovered from a known SNAP header and ciphertext byte, enabling statistical key recovery under weak IV conditions. section 4.3.1 section 4.3.2

Figure 4.10 RC4 internal state: a 256-byte S-box and two pointers, i and j
figure

Shows the mutable 256-byte S-box and the i and j pointers that drive each PRGA iteration. section 4.3.1

How Hacking Cryptography covers it

How deep it goes
Traces pointer updates, swapping, indexed output, and a Go implementation, then applies the first output byte to FMS key recovery.
Examples
Uses Go code, a 256-byte S-box, pointer updates, known SNAP-header bytes, and weak-IV WEP packets.
What it assumes
Assumes familiarity with RC4 key scheduling, modular arithmetic, byte arrays, swapping, and XOR-based stream encryption.
What you can do after
Build RC4 keystream generation and reproduce its XOR-based encryption routine in Go.
How it connects
Connects RC4, key-scheduling algorithm, S-box, keystream, stream cipher, WEP, and the Fluhrer-Mantin-Shamir attack.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hacking Cryptography. The section links point to the parts of the book it draws on.