← Codes you can try

The One-Time Pad

A code whose key is random, as long as the message, and used once.

Add a random letter to every letter of a message. If those random letters stay secret and are never used again, the coded message tells a codebreaker nothing about the message, except how long it is. Try it below, then see how one mistake breaks it.

This page is for learning, not for hiding anything real. Don’t type real secrets or private information. Everything runs in your browser. Nothing you type is sent or kept.

I The idea

Add a random letter to every letter

Give every letter a number, from A = 0 up to Z = 25. A one-time pad is a list of random letters, as long as the message. To code the message, add each pad letter to the message letter in the same place. If the sum goes past 25, wrap round to 0, the way a clock goes from 12 back to 1.

Take the message letter M and the pad letter X. M is 12 and X is 23, which add up to 35. Take away 26 to wrap round and you get 9, which is the letter J. To decode, the person with the same pad takes each pad letter away again: J (9) take away X (23) is −14, which wraps round to 12, and 12 is M.

The four rules

  • Random. Every letter of the pad is equally likely, with no pattern.
  • As long as the message. Every message letter needs a pad letter of its own.
  • Secret. The pad is known to the sender and the receiver, and to nobody else.
  • Used once. A part of the pad that has been used is never used again.

What Shannon proved. In 1949 the mathematician Claude Shannon published a proof about codes like this. Suppose a codebreaker holds a coded message and nothing else. If the four rules hold, then for every possible message of that length there is exactly one pad that would turn it into this code, and every pad was equally likely to have been picked. So the code does not make any possible message more likely than it was before. Shannon’s name for that is perfect secrecy: the codebreaker has gained no information.

The code still gives away how long the message is, and that a message was sent. Filler letters added to a message can hide its exact length. In his paper Shannon noticed the second point and said it could be hidden too: when there is nothing to say, send a coded blank message.

In the same paper he showed the other direction: a code with this property needs at least as many possible keys as there are possible messages. So for messages made of any letters, the pad cannot be shorter than the message.

II Part 1: try it

Code a message with a pad

Follow the steps from 1 to 4. The page opens on an example, and the result changes as you type. Switch to decode: the coded message moves into the message box, and the same pad turns it back. Make a pad is switched off while you decode, so the pad can’t be replaced by a different one.

Code a message with a pad

1. Choose what to do

The letters A to Z are used. Everything else is left out. Don’t type real secrets.

Make a pad draws random letters, as many as your message has, from your browser’s random numbers. The pad on the page when it opens was made once and typed in, so the example is always the same.

E (4) + E (4) = 8 → I

Check: decoding this with the same pad gives back MEETMEATFIVE.

Why spaces and punctuation are left out. A pad is used letter by letter, and a space would show where each word starts and ends. The tool codes up to 64 letters and ignores the rest.

Groups of five. The coded message is shown in groups of five letters to make it easier to read and copy. The groups mean nothing. Accented letters and digits are left out too, like spaces and punctuation, because the pad works on the 26 letters A to Z.

III Part 2: it could say anything

The same code could say anything

This is the coded message from Part 1. Type any other message with the same number of letters. The page works out the pad that would turn the code into your message.

See the pad that makes the code say another message

1. The coded message from Part 1CXYKZ MNLRL PI

12 of 12 letters

3. The pad that does itKEKVG FJWGL CQ

Check: decoding the coded message with this pad gives STOPTHEPLANS.

The pad really used in Part 1 was QTURN INSMD UE. There are 26 to the power of 12 = 95,428,956,661,682,176 possible pads this long, and each one turns the code into a different message.

The pad in the last row is as good a pad as the one that was really used: it is as long as the message and it looks just as random. A codebreaker who holds just the coded message has no way to tell which pad is the real one, so has no way to tell which message is the real one. This works for every length.

IV Part 3: never use a pad twice

What goes wrong when a pad is used twice

Code two messages with the same pad. Each coded letter is a message letter plus a pad letter. Take one coded message away from the other, letter by letter, and the pad letter drops out of the sum: (message 1 + pad) − (message 2 + pad) is just message 1 − message 2.

Code two messages with the same pad

The pad must be at least as long as the longer message.

Code 1 (message 1 with the pad)JKPTZ WJVDL VE

Code 2 (message 2 with the same pad)AVPKB MCCTD HO

The last two rows matchYes. Code 1 − code 2 and message 1 − message 2 are the same 12 letters: JPAJY KHTKI OQ. The pad is in neither.

If message 1 has ATTACK there, message 2 would haveRETREA

Look for letters that read as a word. At most places the letters are nonsense, and that guess is wrong.

The last two rows are the same, and they do not depend on the pad at all. What is left is the two messages mixed together. It does not read as words, but a codebreaker can pull it apart by guessing a word that may be in one message and seeing whether the other message comes out readable. Try it in step 4: slide the guess along.

V Real life

Why it is hard to use

On paper the one-time pad is simple. In real life, each of the four rules is hard to keep.

A truly random pad

Shannon’s proof needs a pad with no pattern at all. The pad button on this page asks your browser for random numbers, which come in as numbers from 0 to 255. The page keeps a number when it is below 234 and tries again when it is not. That is because 256 does not divide evenly by 26: 256 is 9 × 26 with 22 left over, so using the remainder would make A to V a little more likely than W to Z. Throwing away 234 to 255 gives every letter the same chance.

Even so, the pad from a browser is not the kind Shannon meant. MDN, which documents the browser function, says browsers do not use a truly random source: they use a pseudo-random formula started from a seed with enough entropy, which MDN calls suitable for cryptographic purposes. That is fine for learning, and it is why this page cannot give you a real one-time pad.

Getting the pad to the other person

The pad has to reach the receiver in secret, and it is as long as the message. If you want to send a hundred messages, you must hand over a hundred messages’ worth of secret letters to the other person. Crypto Museum calls this delivery the major disadvantage of the one-time pad: a unique pair of pads must be made for each agent and sent out, and fresh pads must keep arriving as the old ones are used up.

Never using a part twice

Crypto Museum’s rules say that two copies of a pad exist, one for each side, and that both are destroyed straight after use. A pad reused even once gives the codebreaker the trick in Part 3. Something like that happened in the Venona story below.

VI History

A little history

  1. 1882Frank Miller’s telegraph code book A Sacramento banker describes the idea.
  2. 1917 to 1919Vernam and Mauborgne Vernam’s teleprinter cipher, filed as a patent in 1918 and granted in 1919. Mauborgne helps shape the key tape.
  3. 1942Pad pages are printed twice More than 35,000 pages of key are printed twice.
  4. 1943Venona begins US codebreakers start on Soviet messages. The work ends in 1980.
  5. Mid-1940sShannon’s confidential report Dated 1945 by Whitfield Diffie and the memorandum’s number, and 1946 by a note in Shannon’s own paper.
  6. 1949Shannon’s proof is published In the Bell System Technical Journal, October 1949.
  7. 1963The Washington–Moscow hotline Agreed on 20 June: a teleprinter link, coded with one-time keying tapes.
  8. 1980Venona ends The project is closed after almost 40 years.

Each bar sits on a line from 1880 to 1980, drawn to scale. Drawn in code.

Frank Miller, 1882. A banker from Sacramento, California, named Frank Miller wrote a book of telegraph codes in 1882. In 2011 the computer scientist Steven Bellovin saw that it describes the one-time pad, about 35 years before the people usually credited with it. Bellovin calls his match for the author tentative: a Sacramento banker who was a founding trustee of Stanford University. He also says nobody has shown that Vernam or Mauborgne ever saw the book.

Vernam and Mauborgne, 1917 to 1919. Gilbert Vernam, an engineer at AT&T, built a teleprinter cipher in which each character is mixed with a character punched on a paper tape. His patent, number 1,310,719, was filed on 13 September 1918 and granted on 22 July 1919. It says the key signals are “preferably” chosen at random, and allows them to spell out letters or words. Joseph Mauborgne, an officer in the US Army Signal Corps, also took part. Sources differ on his rank at the time, so this page gives none. Together the ideas make an automatic one-time pad, though neither man used that name. Accounts differ about who thought of what. Wikipedia credits Mauborgne with seeing that the tape should be completely random. The older story, as Bellovin retells it from David Kahn’s work, has Vernam seeing the need for randomness and Mauborgne the need for a key that does not repeat. Bellovin’s later paper says Vernam most likely thought of the key not repeating, and that Mauborgne helped with the two-tape version and may have suggested randomness. The sources do not agree on the year: Crypto Museum says Vernam invented his cipher in 1917, and Bellovin’s slides say the one-time pad is believed to date from 1918. The patent application is dated 1918.

Shannon, 1949. Shannon’s proof is in the paper “Communication Theory of Secrecy Systems”, in the Bell System Technical Journal for October 1949. It came out of an earlier confidential report, and the sources disagree on its date: the memorandum’s number, MM 45-110-02, and Whitfield Diffie’s preface to Shannon’s papers point to 1945, and Wikipedia gives 1 September 1945, while a note in the 1949 paper gives 1 September 1946. The timeline says the mid-1940s. In the paper, Shannon calls the one-time pad the Vernam system and writes it as a sum of numbers from 0 to 25, wrapped round at 26, with each key number chosen at random and independently, just as this page does.

Venona, 1943 to 1980. Venona was a United States project to read secret Soviet messages. Most of them were coded with one-time pads and could not be read. A history published by the US National Security Agency, in the edition on the CIA’s website, says that for a few months in early 1942 the coding centre of Soviet intelligence printed duplicate copies of the key on more than 35,000 pages, which were then bound into different pads. (The NSA history calls that service the KGB for convenience; in 1942 it was the NKVD or the NKGB.) In autumn 1943, the NSA history says, an Army codebreaker, Lieutenant Richard Hallock, found signs of repeated key pages. That let codebreakers read part of some messages. Duplicate pages were still turning up on one circuit in June 1948. The same history says the flaw was in the printing of duplicates, and not in the random numbers. The NSA history says the reason for the duplicates is unknown, and that most of the duplicate pages were used between 1942 and 1944.

The Washington–Moscow hotline, 1963. The Cuban Missile Crisis of October 1962 showed how much a fast, direct link between the two governments mattered. On 20 June 1963 the United States and the Soviet Union signed an agreement to build one. It was not a red telephone: it was a teleprinter link, which sends typed messages. Norwegian-built machines coded the messages with one-time keying tapes. Each country made its own tapes and delivered them by courier to the other’s embassy. The sources disagree on the start date. The Arms Control Association says the United States sent a test message over it on 30 August 1963. Crypto Museum says it became operational on 13 July 1963.

VII The lesson

The lesson

Used exactly as the four rules say, the one-time pad hides everything but the length. If a pad is reused, even in part, the codebreaker gets the trick in Part 3. It is hard to keep those rules. For real secrets, use modern tools, and treat this page as a way to learn.

The Vigenère cipher is a close cousin. It repeats a short keyword, and the repeats leave patterns. Shannon wrote that a Vigenère cipher whose key is unlimited, never repeats and is chosen at random, letter by letter, is what he calls the Vernam system, the one-time pad. You can also see how a code can be cracked by counting letters, or start with the Caesar cipher.

VIII Sources

Sources

The names and dates above were checked against the pages listed below, opened on 21 November 2026. Most are in at least two of them. A few rest on one page, and the text says which. Where the pages disagree, the page says so. Nothing is copied: the wording is ours.

Shannon’s proof, Theorem 6 and the pages around it, and the Vernam system as a sum of numbers wrapped round at 26: C. E. Shannon, “Communication Theory of Secrecy Systems”, Bell System Technical Journal 28(4), 656–715, October 1949 (opens in a new tab), a copy kept on a university course page. For the date of the earlier confidential report, and the memorandum’s number, Wikipedia, “Communication Theory of Secrecy Systems” (opens in a new tab), and Whitfield Diffie’s preface to Shannon’s papers (opens in a new tab), which says the report was written in 1945.

Frank Miller: Steven M. Bellovin, “Frank Miller: Inventor of the one-time pad”, Cryptologia 35(3), 203–222 (2011) (opens in a new tab) (the list of his history papers, with the abstract) and his slides on Miller’s codebook (opens in a new tab). Crypto Museum, listed below, also dates Miller’s description to 1882.

Vernam’s cipher and patent: US patent 1,310,719, “Secret signaling system” (opens in a new tab), Crypto Museum, “Vernam cipher” (opens in a new tab), and Wikipedia, “Gilbert Vernam” (opens in a new tab), for the credit to Mauborgne for the random tape; Wikipedia’s rank for him is not used here because the sources differ.

The one-time pad and its rules: Crypto Museum, “One-time pad” (opens in a new tab).

Venona: “Venona: Soviet Espionage and the American Response, 1939–1957”, edited by Robert Louis Benson and Michael Warner (National Security Agency, 1996), the introduction, on the CIA’s website (opens in a new tab); the page now rests on that history alone.

The hotline: the agreement of 20 June 1963, in the Avalon Project at Yale (opens in a new tab), Arms Control Association, “Hotline Agreements” (opens in a new tab) and Crypto Museum, “Hotline” (opens in a new tab).

Random numbers in the browser: MDN, “Crypto: getRandomValues() method” (opens in a new tab) and the W3C Web Cryptography API (opens in a new tab).

No photographs are used on this page: every picture is drawn in code.