How to use it
Pick a mode at the top. Text works on the bytes of anything you type or paste, so capitals, digits, accents, symbols and emoji all work. Letters is the pencil-and-paper version with A to Z only. File encrypts any file, Image turns a picture into colour noise, and Key reuse shows what goes wrong when one key is used twice. The Randomness check below compares the original data, the key and the ciphertext.
Controls
- Text and Letters: type, paste or open a text file. Every change of the text gets a fresh key of the right length; Generate new key rolls another. Paste the ciphertext and key on the Decrypt side to get the message back. The arrow buttons walk through the calculation one byte or letter at a time.
- Letters: remove spaces, digits and punctuation (the classic groups of five hide word lengths) or keep them.
- File: choose or drop a file up to 20 MB. Encrypt file gives two downloads, the ciphertext and the key; to decrypt, choose both.
- Image: choose a picture or use the sample, press New key, and download the encrypted picture and the key as PNG files; choose both under Decrypt to get the picture back.
- Key reuse: compare two pictures or messages encrypted with one key, and guess a word to uncover the other message.
- Keyboard: Tab moves between controls; on a mode button, the arrow keys switch modes.
How it works
The Vernam cipher combines each bit of the message P with a bit of the key K using exclusive or (XOR, ⊕), which gives 1 when the two bits differ and 0 when they are equal:
Decryption repeats the operation, because K ⊕ K = 0. In the Letters mode A = 0 … Z = 25, and key letters are drawn without bias: random bytes from 234 to 255 are thrown away, so each letter has a chance of exactly 1/26.
In 1917 Gilbert Vernam built a teleprinter machine that combined each 5-bit character with a character from a punched paper key tape. Joseph Mauborgne saw that the system becomes unbreakable when the tape is random and never used again, and in 1949 Claude Shannon proved it: seeing the ciphertext does not make any message of that length more or less likely. This perfect secrecy holds only if the key is truly random, at least as long as the message, kept secret and never reused. The page uses the browser’s crypto.getRandomValues, a cryptographically secure pseudorandom generator seeded by the operating system, not a physical noise source. Everything runs on your device: nothing is uploaded and nothing you type is saved.
An encrypted file starts with a small hidden header (a fixed marker and the file name) encrypted together with the data, so decryption restores the name and notices a wrong key. Pictures are encrypted in red, green and blue, with transparency flattened onto white, and must be saved as PNG: JPEG changes colour values slightly, and every changed bit of the ciphertext becomes a wrong bit of the picture.
The Randomness check counts how often each value occurs and computes the entropy H in bits per symbol and the index of coincidence IC:
Here ni is the count and pi the share of value i among N symbols. IC is near 1/256 for random bytes and 1/26 for random letters, while English letters give about 0.066 because E, T and A are common. The chi-square test compares the counts with a flat histogram and needs at least five expected counts per value.
Things to try
- Encrypt one letter repeated many times: almost no entropy in, a ciphertext as random as the key out.
- In Letters, compare the index of coincidence of the sample text (near 0.066) with its ciphertext (near 0.038).
- Encrypt a ZIP archive or a photo. Its bytes already look almost random, but compression is not encryption.
- In Key reuse, press New shared key: both ciphertexts change, but their XOR stays the same picture.
- Run the JPEG test in the Image mode and watch decryption fall apart.
Frequently asked questions
Is the one-time pad really unbreakable?
Yes, when all four conditions hold: the ciphertext then reveals only the message length. In practice key handling fails, because making, sharing and destroying long keys safely is hard.
Why is the entropy of my random key below 8 bits?
Because the sample is small. In 30 bytes at most 30 different values can appear, so the measured entropy cannot exceed log2 30 ≈ 4.9 bits. The index of coincidence has no such bias, so it is the better test for short data.
What happens if a key is used twice?
The XOR of the two ciphertexts equals the XOR of the two messages, and a guessed word in one message reveals the other at that spot. In the 1940s, duplicated pad pages let American analysts read part of Soviet intelligence traffic in the Venona project.
Why not use it for everything?
The key must be as long as everything you send and reach the other person secretly in advance. Modern ciphers use short keys; they are secure in practice, though not in Shannon’s perfect sense.
Sources
- Vernam GS (1926). Cipher printing telegraph systems for secret wire and radio telegraphic communications. Transactions of the American Institute of Electrical Engineers 45, 295–301. The teleprinter that combines each character of the message with a character of a key tape.
- Shannon CE (1949). Communication theory of secrecy systems. Bell System Technical Journal 28(4), 656–715. The proof of perfect secrecy for a random key as long as the message.
- Benson RL, Warner M, eds. (1996). Venona: Soviet espionage and the American response, 1939–1957. NSA and CIA. The duplicated one-time pad pages that made the Venona decryptions possible.