One-time pad (Vernam cipher)

Write a message, press the button for a random key as long as the message, and encrypt it letter by letter or byte by byte. The same key decrypts it. Used once and kept secret, such a key makes the ciphertext impossible to read without it.

Work with
Direction
At least as many letters as the message. Other characters in the key are skipped.

Key characters used: 5.

Never use a key twice: two messages encrypted with the same pad can be read together. The random key is made in this browser with crypto.getRandomValues.

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Choose letters (classic pad) or bytes, and the direction.
  2. In letter mode choose the alphabet; the example message for it appears.
  3. Type the message and press New random key: it creates exactly as many key characters as the message needs.
  4. Copy the result and the key. To decrypt, press the button under the result or switch the direction and paste the ciphertext with the same key.

How it works

  • Letters: the alphabet letters are numbered from 0 (A = 0 … Z = 25 for Latin). Encrypting: C = (P + K) mod n; decrypting: P = (C − K) mod n, where n is 26, 33 or 27. Lower case is turned into capitals and accents are dropped (Á → A), except for letters of the alphabet itself such as Ñ or Ё.
  • Bytes: the message is UTF-8, each byte is XORed with a key byte, the ciphertext is hex. Decryption XORs again and reads the bytes as UTF-8.
  • The key must be at least as long as the message; it is used from its first character.

Example

The textbook example HELLO with the key XMCKL:

H E L L O
Message 7 4 11 11 14
Key X 23 M 12 C 2 K 10 L 11
Sum mod 26 30 → 4 16 13 21 25
Ciphertext E Q N V Z

The result is EQNVZ, using 5 key characters. Decrypting EQNVZ with XMCKL gives HELLO again: E 4 − X 23 = −19 → 7 = H, and so on.

Tips

  • Store the key separately from the ciphertext; whoever has both can read the message.
  • Destroy a key once it has been used: re-using it is what broke real one-time pad systems.
  • For bytes mode, both sides need the same hex key; copy it as text, not as a screenshot.

Frequently asked questions

Why is a one-time pad unbreakable?

If the key is truly random, as long as the message, kept secret and used once, every plaintext of the same length is equally likely for a given ciphertext. Claude Shannon proved this property, called perfect secrecy, in 1949.

Then why is it not used everywhere?

The key is as long as all the data you will ever send and must reach the other side securely in advance. That is hard in practice, so modern systems use short keys with ciphers like AES instead.

What happens to spaces and punctuation in letter mode?

They are copied unchanged and use no key, so the result keeps the word lengths. For real secrecy remove spaces and punctuation before encrypting, as classic pad users did.

Is the example key safe to use?

No. It is printed on this page for everyone to see. Press New random key for any real message, and never use the same key twice.

How is the random key made?

With crypto.getRandomValues, the browser's cryptographic random generator, without modulo bias. It is created on your device and never sent anywhere.

More in Developer

All tools in this category: Developer ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.