Autokey Vigenère cipher — the message extends its own key

The autokey cipher works like Vigenère, but after the primer keyword runs out, the plain text itself becomes the key; enter a primer such as QUEENLY and encrypt or decrypt.

Live demo · real result from this tool
Direction

Result

Qnxepv yt wtwp

Processed on your device — nothing is uploaded.

How to use the autokey Vigenère tool

  1. Choose the Direction: Encrypt or Decrypt.
  2. Enter the Primer keyword. Only its letters count; the default is QUEENLY.
  3. Type into Your text.
  4. Copy the Result. To decrypt, use the same primer and switch the direction.

What it does and when to use it

The autokey cipher was described by Blaise de Vigenère in the 1500s, and it is the version he actually proposed; the repeating-key cipher that carries his name today is simpler. The idea is to stop the key from repeating by feeding the message back into it. That defeats the classic attack on the Vigenère cipher, which looks for repeated patterns spaced by the key length.

Use it for puzzles, geocaches and cryptography lessons, especially to show how a small change to a cipher can block one attack and open another. It is not suitable for protecting real information. Related tools: the Beaufort cipher reverses the arithmetic, and the Gronsfeld cipher uses a digit key.

How it works

Number the letters A = 0 to Z = 25. The key stream starts with the primer letters. For each letter of the message:

Encrypt:  C = (P + K) mod 26,  then add P to the end of the key stream
Decrypt:  P = (C − K) mod 26,  then add P to the end of the key stream

In both directions the plain letter is added, which is why the receiver, who recovers the plain text letter by letter, can rebuild the same key stream.

The textbook example lines up like this:

Plain:  A T T A C K A T D A W N
Key:    Q U E E N L Y A T T A C
Cipher: Q N X E P V Y T W T W P

Only A to Z and a to z are changed, and each keeps its case. Other characters are copied across and never enter the key stream. The tool runs in your browser.

Worked examples

Results from the tool:

ATTACKATDAWN                  primer QUEENLY            →  QNXEPVYTWTWP
Meet me at 9, by the gate!    primer Key                →  Wicf qi tf 9, fy mic zhxk!
Wicf qi tf 9, fy mic zhxk!    primer Key, Decrypt       →  Meet me at 9, by the gate!
Hi                            primer 7                  →  The key needs at least one letter.

Compare the second line with ordinary Vigenère and the key KEY: both start “Wic”, because the first three letters use the primer, but from the fourth letter on autokey uses “meetmeat…” as its key and the results part ways.

Limits and tips

  • A longer primer hides more of the message start, which is where guessing attacks begin.
  • Because spaces are kept, word lengths show. Remove spaces first if that matters.
  • Accented letters are not encrypted and do not join the key stream.

Frequently asked questions

What is the primer?
It is the short keyword that starts the key. Once its letters are used up, the key continues with the letters of your plain text. With primer QUEENLY and message ATTACKATDAWN, the full key is QUEENLYATTAC.
Why is autokey stronger than ordinary Vigenère?
Ordinary Vigenère repeats its keyword, and those repeats let an attacker find the key length. Autokey never repeats, so that attack does not work. It can still be broken, because part of the key is ordinary English text that can be guessed. It is a puzzle and teaching cipher, not real protection.
Why does one wrong letter spoil the rest of my decryption?
When decrypting, each recovered letter becomes part of the key for a later letter. If one ciphertext letter is mistyped, the wrong plain letter it gives feeds into the key, and the error repeats further along. Check the ciphertext carefully, character by character.
What happens to spaces, digits and punctuation?
They pass through unchanged and are not added to the key. Only the letters A to Z and a to z are encrypted, each keeping its case.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close