Autokey Cipher
Enter a short primer and a message, and the tool encodes or decodes it with the Vigenère autokey cipher — the key that never repeats because it continues with the message itself. You see the key line up under the text and the sum behind each letter. Free, no sign-up, and nothing leaves your browser.
A short keyword that only starts the key. After it, the key carries on with the message itself, so it never repeats.
Plain-text autokey is the classical cipher and the one puzzle sites mean by “autokey”. The cipher-text form is the other version found in textbooks; both sides must pick the same one.
Working
The key, letter by letter — the first 12 letters
| 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 |
The first 7 key letters (shaded) are the primer; after that each key letter is the plain-text letter 7 places back.
- Letters are numbered A = 0, B = 1 … Z = 25, and every sum wraps around at 26.
- Encoding: cipher letter = plain letter + key letter.
- The key is the primer followed by the plain text, so while decoding every letter you recover joins the key.
Vigenère square
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| B | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A |
| C | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B |
| D | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C |
| E | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D |
| F | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E |
| G | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F |
| H | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G |
| I | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H |
| J | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I |
| K | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J |
| L | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K |
| M | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L |
| N | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M |
| O | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N |
| P | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
| Q | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P |
| R | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q |
| S | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R |
| T | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S |
| U | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T |
| V | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U |
| W | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V |
| X | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W |
| Y | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X |
| Z | Z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y |
Row = key letter, column = plain letter, cell = cipher letter. Select a letter below to light it up: its row and column turn blue and the cell where they meet turns amber.
| Plain letter | Key letter | Arithmetic | Cipher letter |
|---|---|---|---|
| Q | 0 + 16 = 16 | Q | |
| U | 19 + 20 = 39 ≡ 13 | N | |
| E | 19 + 4 = 23 | X | |
| E | 0 + 4 = 4 | E | |
| N | 2 + 13 = 15 | P | |
| L | 10 + 11 = 21 | V | |
| Y | 0 + 24 = 24 | Y | |
| A | 19 + 0 = 19 | T | |
| T | 3 + 19 = 22 | W | |
| T | 0 + 19 = 19 | T | |
| A | 22 + 0 = 22 | W | |
| C | 13 + 2 = 15 | P |
How to Use the Autokey Cipher Tool
- 1. Choose a primer. It is a short keyword, such as QUEENLY, that starts the key. Only its letters count.
- 2. Pick what continues the key. The classic autokey uses the plain text; the cipher-text form is offered for textbooks that use it. Both sides must agree.
- 3. Type the message and choose Encode or Decode. Spaces, digits and punctuation pass through unchanged and do not use key letters.
- 4. Watch the key build. The key table lines up the plain text, the key and the cipher text, with the primer shaded; select a letter in the working table to see it in the square.
How the Autokey Cipher Works
The autokey cipher is a Vigenère cipher with one change: the key does not repeat. The sender and receiver agree on a short primer, and the key is the primer followed by the message itself. With A = 0 to Z = 25, each cipher letter is C = P + K (mod 26), exactly as in the Vigenère cipher, and decoding subtracts the key again: P = C − K.
Decoding works because the key is always one step ahead of the reader. The primer decodes the first few letters; those plain letters then become the next key letters, which decode the following letters, and so on to the end. Take the primer QUEENLY and the message ATTACKATDAWN:
| Plain | Key | Sum | Cipher |
|---|---|---|---|
| A (0) | Q (16) | 0 + 16 = 16 | Q |
| T (19) | U (20) | 19 + 20 = 39 ≡ 13 | N |
| T (19) | E (4) | 19 + 4 = 23 | X |
| A (0) | E (4) | 0 + 4 = 4 | E |
| C (2) | N (13) | 2 + 13 = 15 | P |
The whole message becomes QNXEPVYTWTWP, the same answer the Wikipedia article on the autokey cipher gives for this example. The key is QUEENLY followed by ATTACKATDAWN; its eighth letter, A, is the message's first letter. The tool shows that key line directly under your text so you can see where the primer ends and the message takes over.
A Short History of the Autokey Cipher
The idea of letting the message key itself is usually credited to the Italian polymath Girolamo Cardano in the mid-1500s. His version restarted the key at each word, which left the first word as hard to recover for the reader as for an enemy cryptanalyst, according to David Kahn's history The Codebreakers. In 1586 Blaise de Vigenère described a cleaner scheme in his Traicté des chiffres: a single priming letter, then a key that runs on through the message without restarting. That is the autokey cipher as it is taught today. The better-known repeating-keyword cipher that carries Vigenère's name is a different, earlier invention by Giovan Battista Bellaso — the label was attached to it in the 19th century by mistake.
How the Autokey Cipher Is Broken
A non-repeating key defeats the attacks that destroy the Vigenère cipher. Kasiski examination looks for repeated fragments spaced a key-length apart, and the index of coincidence looks for a period; an autokey message has neither. But the key is made of ordinary language, and that is the weakness. A cryptanalyst guesses a common word such as THE, slides it along the cipher text and subtracts it; wherever the result is readable English, that fragment is probably the key too, and it reveals more plain text one primer-length further on. Each correct guess feeds the next, and the message unravels quickly. The first letters, enciphered with the primer alone, are an ordinary short-key Vigenère. Another drawback is error propagation: one wrong letter in encoding or copying spoils every letter after it.
For puzzles and teaching, not secrecy
Autokey is a real step beyond a repeating key, but it has been broken for generations. Use it to learn how running keys work, never to protect anything private.
Frequently Asked Questions
- What is the autokey cipher?
- The autokey cipher is a polyalphabetic substitution cipher in which the key is a short primer followed by the message itself. Each letter is enciphered with the Vigenère rule, C = P + K (mod 26), so the key is as long as the message and never repeats.
- How do you decrypt an autokey cipher?
- Write the primer, subtract each key letter from the matching cipher letter to get a plain letter, then append that plain letter to the key and carry on. After the primer is used up, the key is simply the plain text you have already recovered. This tool does it for you when you choose Decode.
- What is the difference between the autokey and Vigenère ciphers?
- Vigenère repeats a keyword for the whole message, while autokey uses the keyword once and then continues with the message. That removes the repeating pattern that Kasiski examination and the index of coincidence rely on, which is why autokey resisted those attacks.
- Is the autokey cipher secure?
- No. Because the key is made of the plain text, a guessed word reveals both a piece of the message and a piece of the key, and the pieces chain together. Crib-dragging with common words breaks it by hand, and software recovers the primer from a few hundred letters.
- How long should the primer be?
- Any length from one letter up. Vigenère's original used a single letter, and the American Cryptogram Association's example uses the six-letter PRIMER. A longer primer hides a few more opening letters, but it does not change the underlying weakness: after the primer, the key is the plain text itself.
- What is a cipher-text autokey?
- In the cipher-text form the key continues with the cipher text instead of the plain text. It is easier to decode, since the whole key is visible in the cipher text, but that also means anyone can read it, so it adds almost nothing over a short Vigenère key. Both sides must choose the same version.