The one-time pad is the only encryption proven mathematically unbreakable. It is also completely impractical. Here is how XOR works, why Shannon proved it secure, and why nobody uses it.
The one-time pad is the only encryption proven mathematically unbreakable. It is also completely impractical for almost every real-world use case. The gap between theoretical perfection and practical deployment is the entire history of modern cryptography.
Claude Shannon proved in 1949 that the one-time pad provides perfect secrecy, meaning the ciphertext reveals zero information about the plaintext. No computational power, no quantum computer, no future algorithm can break a properly implemented one-time pad. The catch: the key must be truly random, as long as the message, and never reused. Violate any of these three conditions and the security proof collapses.
You can experiment with the XOR operation that powers the one-time pad using the Vernam cipher tool.
The one-time pad is built on the XOR (exclusive OR) operation. XOR takes two bits and outputs 1 if exactly one input is 1, otherwise 0:
``
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
``
XOR has two properties that make it useful for encryption:
1. Self-inverse: A XOR A = 0. If you XOR a value with itself, you get zero.
2. Associative and commutative: A XOR B XOR C = C XOR A XOR B. Order does not matter.
These properties mean that if you XOR plaintext with a key to get ciphertext, XORing the ciphertext with the same key gives back the plaintext:
``
ciphertext = plaintext XOR key
plaintext = ciphertext XOR key
``
Because (plaintext XOR key) XOR key = plaintext XOR (key XOR key) = plaintext XOR 0 = plaintext.
The XOR calculator demonstrates this operation on binary and hexadecimal values. The Vernam cipher tool applies it to text using a character-level key.
Gilbert Vernam patented the cipher in 1919 for use with paper tape teleprinter systems. Vernam's original system XORed the plaintext character stream with a key character stream punched on a loop of paper tape. Joseph Mauborgne realized that if the key tape was truly random and used only once, the system was unbreakable. The combination of Vernam's mechanism and Mauborgne's insight produced the one-time pad.
In 1949, Claude Shannon published Communication Theory of Secrecy Systems in the Bell System Technical Journal. He proved that the one-time pad provides perfect secrecy, a formal cryptographic definition meaning that the ciphertext and plaintext are statistically independent.
The proof is straightforward. If the key is truly random and as long as the message, then for any plaintext P and any ciphertext C, there exists exactly one key K such that P XOR K = C. Since K is uniformly random, every ciphertext is equally likely regardless of the plaintext. An attacker who sees the ciphertext gains zero information about the plaintext.
Formally, perfect secrecy requires that H(P | C) = H(P), where H is Shannon entropy. The conditional entropy of the plaintext given the ciphertext equals the entropy of the plaintext alone. Knowing the ciphertext does not reduce uncertainty about the plaintext at all.
This is an information-theoretic result, not a computational one. AES is secure because no known algorithm can break it in reasonable time (computational security). The one-time pad is secure because there is insufficient information in the ciphertext to determine the plaintext, regardless of available time or computing power (information-theoretic security).
The Wikipedia article on Shannon's 1949 paper summarizes the proof and its historical context. Shannon's work established the mathematical foundations of modern cryptography.
The one-time pad's security proof holds only if three conditions are met simultaneously. Violating any one breaks the cipher.
1. The key must be truly random: Pseudorandom number generators produce sequences that look random but are deterministic. If the attacker can guess or reconstruct the PRNG state, they can reproduce the key. True randomness requires a physical source: radioactive decay, thermal noise, quantum measurements. The random string generator uses the browser's CSPRNG, which is suitable for most purposes but is still pseudorandom.
2. The key must be as long as the message: The key must be at least as long as the plaintext. If the key is shorter and repeats, the cipher becomes a Vigenere variant, vulnerable to frequency analysis and the Kasiski examination. A 1-megabyte message requires a 1-megabyte key. A 1-gigabyte file requires a 1-gigabyte key.
3. The key must never be reused: Using the same key for two messages produces a two-time pad. XORing the two ciphertexts cancels the key and leaves the XOR of the two plaintexts, which is readable using crib dragging. This is the same vulnerability that breaks nonce reuse in stream ciphers, described in the cryptographic nonce post.
All three conditions must hold simultaneously. The key must be random, long enough, and used once. Failing any one destroys the security proof.
The key distribution problem is the one-time pad's fatal practical weakness. To send a 1-GB file securely, you must first deliver a 1-GB key to the recipient through a secure channel. If you have a channel secure enough to deliver a 1-GB key, you could use it to deliver the message itself.
This circular dependency is why the one-time pad is rarely used despite being the only proven unbreakable cipher. The practical alternatives (AES, RSA, TLS) trade information-theoretic security for computational security, which is sufficient given the limits of known computing power.
The Venona project: The most famous real-world break of a one-time pad system was the US Venona project (1943-1980). Soviet intelligence used one-time pads for diplomatic and espionage communications. Due to supply shortages during WWII, some pad pages were reused across different messages. The US National Security Agency detected these reuses and exploited the two-time pad vulnerability to decrypt thousands of Soviet messages. The Venona decrypts identified Soviet spies in the US and UK, including Klaus Fuchs, Julius Rosenberg, and Alger Hiss.
The Venona break was not a break of the one-time pad algorithm. It was a break of the key management. The Soviets violated the "never reuse" requirement, and the NSA exploited the resulting two-time pad. The Wikipedia article on the one-time pad covers Venona and other historical uses.
Modern uses: The one-time pad is still used in specific high-security scenarios where key distribution is feasible. The Moscow-Washington hotline originally used one-time pads for teletype communication, with pads delivered by diplomatic courier. Some intelligence agencies reportedly use one-time pads for the most sensitive communications, with key material delivered physically.
The Vigenere cipher is a one-time pad with a short, repeating key. When the key is a single character, Vigenere reduces to the Caesar cipher. When the key is as long as the message and truly random, Vigenere is the one-time pad. Every attack on Vigenere (Kasiski examination, Index of Coincidence, frequency analysis) exploits the gap between Vigenere's short repeating key and the one-time pad's long random key.
The stream cipher vs. block cipher post explains how modern stream ciphers like ChaCha20 approximate the one-time pad by generating a pseudorandom keystream from a short key. The keystream is XORed with the plaintext, just like a one-time pad. The difference is that the keystream is pseudorandom, not truly random, so the security is computational rather than information-theoretic.
The encoding vs. encryption vs. hashing post covers the broader distinction between these operations, which is a common source of confusion for developers new to cryptography.
A one-time pad is an encryption system where the plaintext is XORed with a truly random key that is as long as the message and used only once. It is the only cipher proven to provide perfect secrecy, meaning the ciphertext reveals zero information about the plaintext. The security is information-theoretic, not computational.
The key distribution problem. To send a 1-GB message, you must first securely deliver a 1-GB key to the recipient. If you have a channel secure enough to deliver the key, you could use it to deliver the message itself. This circular dependency makes the one-time pad impractical for most real-world applications.
Reusing a key for two messages creates a two-time pad. XORing the two ciphertexts cancels the key and leaves the XOR of the two plaintexts. This is readable using crib dragging, a technique where you try common words against the XOR to recover both messages. The Soviet Union made this mistake during WWII, and the US Venona project exploited it to decrypt thousands of messages.
Claude Shannon proved in his 1949 paper 'Communication Theory of Secrecy Systems' that the one-time pad provides perfect secrecy. He showed that if the key is truly random, as long as the message, and used once, the ciphertext and plaintext are statistically independent. No amount of computing power can break a properly implemented one-time pad.
The Vigenere cipher is a one-time pad with a short, repeating key. When the Vigenere key is as long as the message and truly random, it becomes a one-time pad. All attacks on Vigenere (Kasiski examination, Index of Coincidence, frequency analysis) exploit the gap between Vigenere's short repeating key and the one-time pad's long random key.
Vernam Cipher (One-Time Pad)
Encrypt and decrypt text using the Vernam cipher, the XOR-based one-time pad that Shannon proved is perfectly secure.
Vigenère Cipher
Polyalphabetic substitution cipher using a keyword for enhanced encryption.
XOR Calculator
Perform bitwise XOR operations on multiple numbers with binary and hexadecimal representations.
Random String Generator
Generate secure random strings for passwords and tokens.
The Difference Between Encoding, Encryption, and Hashing
Base64 is not encryption. This guide defines encoding, encryption, and hashing precisely, runs the same input through each, and explains when to use which in production systems.
Stream Ciphers vs. Block Ciphers: What's the Difference?
A block cipher encrypts in fixed-size chunks. A stream cipher encrypts one byte at a time. The difference changes everything from padding to nonce reuse. Here is how they compare.
What Is a Cryptographic Nonce? (And Why Reusing One Breaks Everything)
Sony reused a nonce in PS3 code signing and hackers extracted the master key. PuTTY had biased nonces in 2024. Here is what a nonce is and why reusing one destroys cryptographic security.