liveBook · Manning

One-time pad

As explained in Hacking Cryptography

A one-time pad is an encryption technique that combines plaintext with a truly random key of equal length that is never reused.

A one-time pad encrypts plaintext by XORing it with a truly random key equal in length to the message. With a unique key, it provides mathematically perfect security. section 4.1.2 section 4.4

Implement the construction correctly, then preserve its security properties:

  • Generate fresh random bits with a true random number generator; an 11-byte message such as “HELLO WORLD” requires 88 random key bits. section 4.1.2
  • XOR the plaintext and key to produce ciphertext, and XOR the ciphertext with the original key to reverse the operation. section 4.1.2 section 4.4
  • Never reuse a key: communicating it securely requires transporting as many secret bits as the message, limiting large-scale practicality. section 4.1.2 section 4.4

Why key reuse fails

If two ciphertexts use the same key, XORing them cancels the key and reveals the XOR of the two plaintexts. Known plaintext similarly lets an attacker recover the corresponding key bytes; related weaknesses helped break WEP. section 4.1.2 section 4.4

Equation 4.3
\[\begin{aligned} \begin{aligned} \text{Plaintext}_1 &\oplus \text{Key} &=& \; \text{Ciphertext}_1 \\ \text{Plaintext}_2 &\oplus \text{Key} &=& \; \text{Ciphertext}_2 \\ \text{Plaintext}_1 &\oplus \text{Plaintext}_2 &=& \; \text{Ciphertext}_1 \oplus \text{Ciphertext}_2 \\ \end{aligned} \label{equation:encrypt-xor-key-reuse} \end{aligned}\]

Trace how reusing one key transforms two plaintexts into an attacker-visible XOR combination. section 4.1.2

How Hacking Cryptography covers it

How deep it goes
Defines the construction, derives XOR attacks, and explains key transport limits without detailing a complete production implementation.
Examples
Uses “HELLO WORLD,” guessed greetings, XOR equations, and WEP compromise to demonstrate construction and failure.
What it assumes
Assumes basic plaintext, ciphertext, key, and XOR notation while deriving the relevant reversals and attack relationships.
What you can do after
Build it from scratch with random equal-length keys, apply XOR correctly, and diagnose known-plaintext or key-reuse exposure.
How it connects
Connects one-time pads to XOR encryption, known-plaintext attacks, key reuse, stream ciphers, keystreams, and WEP.

Also explained in

Compare how 2 books explain one-time pad →

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.