Grow a long pseudo-random KEYSTREAM from a short key, then XOR it byte-by-byte into your message — that’s a stream cipher, the fast engine behind Wi-Fi and TLS. XOR again with the same keystream and the message pops back out. But there’s a deadly rule: NEVER reuse a keystream. XOR two messages encrypted with the same stream and the key cancels, leaking their combination — the mistake that broke WEP. Slide to see encryption, and then the leak.
A stream cipher expands a short key (and nonce) into a long pseudo-random KEYSTREAM, then encrypts by XOR: c=p⊕ks; decryption is the same XOR, p=c⊕ks. It is fast, needs no padding, and encrypts bit-by-bit (RC4, ChaCha20, and the [[the-one-time-pad|one-time pad]] as the ideal case). The absolute rule is NONCE/KEYSTREAM UNIQUENESS: reuse the same keystream on two messages and c₁⊕c₂=p₁⊕p₂ — the key cancels, exposing the plaintexts’ XOR (the flaw that broke WEP). A fail-loud self-check throws unless decryption inverts encryption AND c₁⊕c₂ equals p₁⊕p₂ under reuse. ◆ real cryptography, node-verified.
A stream cipher gives confidentiality only — malleable without a separate MAC ([[the-hmac]]) — and its security rests on the keystream being unpredictable and NEVER reused; a toy PRNG stands in here for a real one (ChaCha20). The XOR roundtrip and the reuse-leak identity are exact.