The Vernam cipher is the one-time pad — the only cipher that cannot be broken if the key is random, used once and at least as long as the text. Encrypt by addition modulo the alphabet or by XOR of letter numbers, and generate a random key of the right length right in your browser.
Everything runs in your browser — the text goes nowhere
The letter number counted from one and its 5-bit form. XOR adds bits without carrying: 1 ⊕ 1 = 0.
03
How it works
Adding the key
attack + lemonx → lxfoph
The number of each text letter is added to the number of the key letter, modulo 26. Decoding subtracts it.
XOR of numbers
h ⊕ k: 8 ⊕ 11 = 3 → c
The numbers are written in binary and added bit by bit. The same key applied to the ciphertext numbers returns the letters.
Why it cannot be broken
key length = text length
A random key, as long as the text and used only once, makes every decoding of the same length equally likely.
04
Frequently asked questions
Each letter of the text gets a key letter added to it: the numbers are summed and the remainder after division by the alphabet length is taken. ATTACK with the key LEMONX becomes LXFOPH. The second option is XOR: letter numbers are written in binary and added bit by bit. Either way, the key must be at least as long as the text.
If the key is random, as long as the text and used only once, the ciphertext is equally likely to mean any text of the same length. By choosing a key one can get both “yes” and “no”, and nothing tells which is real. So trying keys is useless even with unlimited computing power. The weak spot is not the cipher but the keys: they must be made, delivered and destroyed.
Modulo adds letters around the alphabet circle, like the Vigenère cipher, and the ciphertext stays in letters. XOR writes letter numbers in binary — five bits for English — and adds them without carrying: H (8) ⊕ K (11) = 3, which is C. The result often falls outside the alphabet, so the ciphertext is written as numbers. XOR is its own inverse: the same key returns the text.
The cipher stops being secure. If the key is shorter than the text and repeats, it is the Vigenère cipher, which is broken through the repeats. If one key encrypts two messages, their difference no longer depends on the key and exposes both texts. That is how American cryptanalysts in the Venona project read part of the Soviet traffic of the 1940s sent with reused pads.
Gilbert Vernam proposed the cipher for teleprinters in 1917, and Joseph Mauborgne added the requirement of a random one-time key. Claude Shannon proved its perfect secrecy in a classified 1945 paper published in 1949. Independently, the Soviet engineer Vladimir Kotelnikov proved the same in a secret report of 1941.
You need the same key as the sender. In modulo mode the key is subtracted: open the “Decrypt” tab and paste the ciphertext and the key. XOR has no tab: paste the ciphertext numbers and the same key, and XOR returns the letters. Without the key it cannot be decrypted — that is the point of a one-time pad, which is why the key never goes into the “Share” link.