Introduction
The Vernam cipher is the only encryption method that Claude Shannon mathematically proved to be unbreakable. When the key is truly random, used exactly once, and at least as long as the message, the ciphertext reveals zero information about the plaintext. Gilbert Vernam patented the XOR-based mechanism in 1919 (U.S. Patent 1,310,719) for AT&T teleprinter traffic, and Joseph Mauborgne recognized that a non-repeating random key tape would make the system impossible to crack. This tool lets you XOR any text with a key directly in your browser and inspect the hex output. Paste your message and key below to see the one-time pad in action.
What this tool does
- XORs each character of your plaintext with the corresponding character of a key you provide, outputting hex-encoded ciphertext.
- Decrypts by XORing hex ciphertext with the same key, recovering the original plaintext byte for byte.
- Warns you when the key is shorter than the message, since key reuse or cycling breaks the perfect secrecy property.
- Handles full Unicode input by operating on UTF-16 code units, so ASCII, accented characters, and symbols all work.
- Runs entirely client-side. Your plaintext and key never leave your browser.
How this tool works
The tool converts both your message and key into sequences of character codes. In encrypt mode it XORs each message code with the corresponding key code (cycling the key if it is shorter) and formats the result as a two-digit hex string. In decrypt mode it parses the hex input back into bytes, XORs each with the key, and renders the result as text.
A warning appears below the settings panel when your key is shorter than the plaintext. This matters because the security proof only holds when the key is at least as long as the message. The swap button flips between encrypt and decrypt while preserving your input, so you can round-trip a message to verify correctness.
How the cipher or encoding works
The Vernam cipher operates on a simple principle: C = P XOR K, where C is ciphertext, P is plaintext, and K is the key. XOR is its own inverse, so applying the same key to the ciphertext recovers the plaintext: P = C XOR K. No information about P leaks into C as long as K is uniformly random, used once, and equal in length to P.
Frank Miller first described the one-time pad concept in 1882 for telegraphic codes. Gilbert Vernam built the electrical implementation at AT&T in 1917, patented in 1919, using punched paper tape to XOR Baudot-coded characters with a key stream. Joseph Mauborgne, then a U.S. Army Signal Corps captain, realized that a truly random, non-repeating key tape would make the cipher unbreakable. Shannon formalized this in his 1949 Bell System Technical Journal paper "Communication Theory of Secrecy Systems," proving that the one-time pad achieves perfect secrecy: the posterior probability of any plaintext given the ciphertext equals its prior probability.
The practical bottleneck is key distribution. Generating and securely sharing a random key as long as every message is logistically expensive, which is why one-time pads have been limited to high-stakes channels like the Moscow-Washington hotline. A 2024 IACR ePrint paper by Adrian Neal (2024/1145) proposed a quantum-noise-based key distribution scheme to make Vernam-style encryption practical in browser applications, showing the concept still drives research today.
How to use this tool
- Enter your key in the key field. Any text works, but for genuine one-time pad security use a random string at least as long as your message.
- Type or paste your plaintext into the input area when encrypting, or paste hex ciphertext when decrypting.
- Select Encrypt to produce hex output, or Decrypt to recover plaintext from hex.
- Watch the output update instantly. If you see an amber warning, your key is too short for true one-time pad security.
- Use the swap button to switch direction without losing your input, then copy the result when done.
Real-world examples
Cryptography homework: demonstrating perfect secrecy
A student encrypts the message "ATTACK" with the random key "XMCKLZ". Each character code is XORed: A (65) XOR X (88) = 25, which outputs as hex "19". The professor then shows that the same ciphertext "19" could correspond to any other plaintext letter with a different key, proving the ciphertext alone reveals nothing.
CTF challenge: recovering a reused key
A CTF challenge provides two ciphertexts encrypted with the same key. The solver XORs the two ciphertexts together, which cancels the key and produces the XOR of the two plaintexts. From there, crib-dragging common English words reveals both messages. This demonstrates why key reuse destroys the one-time pad's security guarantee.
Secure messaging prototype with pre-shared pads
Two parties meet in person and exchange a USB drive containing 1 GB of random data generated from atmospheric noise. They use successive chunks as one-time pad keys for future messages. Each message consumes key material equal to its length, and they track the current offset. This is the same principle behind the Moscow-Washington hotline, which used one-time tape for decades.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| Vernam / one-time pad | Very low (XOR) | Theoretically perfect secrecy with random, single-use keys |
| Caesar cipher | Very low | Educational shift cipher, trivially broken by brute force |
| Vigenere cipher | Medium | Polyalphabetic substitution with repeating keyword |
| AES-256 (modern) | High | Computational security for real-world applications |
Limitations or considerations
The one-time pad's security depends on three strict conditions: the key must be truly random (not pseudorandom), at least as long as the message, and never reused. Violating any one of these breaks the cipher. Key reuse is catastrophic: XORing two ciphertexts that share a key cancels it out, exposing the XOR of the two plaintexts. Generating true randomness is hard in software; Web Crypto's crypto.getRandomValues() provides cryptographically strong random numbers in the browser, but most general-purpose PRNGs do not qualify. Key distribution is the other bottleneck. You must securely deliver a key as long as the message itself, which often costs as much as delivering the message. For practical security, use AES-GCM via the Web Crypto API instead.
Frequently asked questions
Is the Vernam cipher the same as the one-time pad?
The Vernam cipher is the XOR-based implementation of the one-time pad. Vernam patented the mechanism in 1919. The term one-time pad refers to the broader concept, which Frank Miller described in 1882 using modular addition. When the key is random, used once, and as long as the message, both achieve perfect secrecy.
Can the one-time pad ever be broken?
Not by cryptanalysis. Shannon proved in 1949 that a correctly used one-time pad has perfect secrecy: the ciphertext contains no information about the plaintext. However, if the key is reused, not truly random, or shorter than the message, the cipher becomes vulnerable. Key reuse is the most common failure mode.
Why is key reuse so dangerous?
If two messages are encrypted with the same key, XORing the two ciphertexts cancels the key and yields the XOR of the two plaintexts. An attacker can then use techniques like crib-dragging to recover both messages. This is how the Venona project broke Soviet one-time pad traffic in the 1940s and 1950s.
How do I generate a truly random key?
Use a hardware random number generator or a cryptographically secure source like crypto.getRandomValues() in the browser. Standard Math.random() is not secure. For physical randomness, atmospheric noise, radioactive decay, or quantum effects provide true randomness.
Is the one-time pad used in practice today?
Rarely, and only for the highest-security channels. The key distribution cost is prohibitive for most applications. The Moscow-Washington hotline used one-time tape for decades. Research continues: a 2024 IACR paper proposed quantum-noise-based key distribution to make Vernam encryption practical in web applications.
Conclusion
The Vernam cipher is the only encryption scheme with a mathematical proof of unbreakability. Its XOR mechanism is trivial to implement, but the key management requirements, random generation and secure distribution of key material equal in length to every message, limit it to niche high-security scenarios. This tool shows the core operation in action and warns you when the key falls short of one-time pad requirements. For everyday encryption needs, use AES-GCM through the Web Crypto API. To explore related ciphers on this site, try the Vigenere cipher or the XOR calculator.