Autokey Cipher
Free online autokey cipher: a Vigenère-style cipher whose key is your keyword followed by the message itself. Encrypt, decrypt, and follow a worked example.
Autokey cipher: the answer in one line
The key is your keyword followed by the message itself, and each letter is shifted by the matching key letter (A = 0 … Z = 25, mod 26). With keyword QUEENLY, ATTACK AT DAWN becomes QNXEPV YT WTWP. Without the spaces that is QNXEPVYTWTWP, the ciphertext given for this keyword and message in the Wikipedia article on the autokey cipher. To decode, use the keyword to recover the first letters, then use each recovered letter as key for a later one.
By Hommer Zhao
How to Use Autokey Cipher
- Enter plaintext and a letters-only keyword.
- Choose Encrypt; the default keyword is QUEENLY and spaces do not consume key characters.
- For decryption, switch modes and supply the same keyword used to encrypt.
- Keep Preserve Spaces on for matching punctuation and spacing, then copy the result.
The component starts with the keyword, then extends the keystream with plaintext letters. Each alphabetic character is shifted by its corresponding keystream letter.
Examples
Keyword QUEENLY — plaintext:
ATTACK AT DAWN
Output:
QNXEPV YT WTWP
Keyword KEY — plaintext:
HELLO
Output:
RIJSS
How the autokey is built
The key is your keyword followed by the message itself. With keyword KEY and the message ATTACK AT DAWN, the key starts K-E-Y and then continues with the plaintext letters: KEYATTACKATD. Only letters count, so spaces do not use up key characters. Each letter is then shifted exactly as in the Vigenère cipher, with A = 0 through Z = 25 and the sum taken mod 26.
The difference from Vigenère is only the key: a repeating keyword there, keyword-then-plaintext here. That one change means the key never repeats, however long the message is.
Worked example: ATTACK AT DAWN with keyword KEY
Every value below is what this tool computes. Position, plaintext letter, key letter (from the keyword for the first three, then from the plaintext), the sum, and the resulting ciphertext letter:
| # | Plain | Key | Plain + Key (mod 26) | Cipher |
|---|---|---|---|---|
| 1 | A | K | 0 + 10 = 10 | K |
| 2 | T | E | 19 + 4 = 23 | X |
| 3 | T | Y | 19 + 24 = 43 → 17 | R |
| 4 | A | A | 0 + 0 = 0 | A |
| 5 | C | T | 2 + 19 = 21 | V |
| 6 | K | T | 10 + 19 = 29 → 3 | D |
| 7 | A | A | 0 + 0 = 0 | A |
| 8 | T | C | 19 + 2 = 21 | V |
| 9 | D | K | 3 + 10 = 13 | N |
| 10 | A | A | 0 + 0 = 0 | A |
| 11 | W | T | 22 + 19 = 41 → 15 | P |
| 12 | N | D | 13 + 3 = 16 | Q |
ATTACK AT DAWN becomes KXRAVD AV NAPQ. Notice the key letters from position 4 onward are just the plaintext moved three places to the right (A-T-T-A-C-K-A-T-D).
Decoding it back, step by step
- Subtract the keyword from the first three ciphertext letters: K−K = A, X−E = T, R−Y = T. That gives ATT.
- Those three letters are now the key for the next three: A, V, D minus A, T, T gives A, C, K. So far ATTACK.
- ACK is the key for the next three: A, V, N minus A, C, K gives A, T, D. The plaintext is now ATTACKATD.
- ATD is the key for the last three: A, P, Q minus A, T, D gives A, W, N. The full message is ATTACK AT DAWN.
Each block of decrypted text becomes the key for the next block, so you must have the exact keyword to begin the chain. Try it in the tool above: paste KXRAVD AV NAPQ, switch to Decrypt, and enter KEY.
Autokey vs Vigenère on the same message
Same message (ATTACK AT DAWN) and same 7-letter keyword (QUEENLY), two different keys:
| Cipher | Key used | Ciphertext |
|---|---|---|
| Vigenère | QUEENLY QUEEN | QNXEPVY JXEAA |
| Autokey | QUEENLY ATTAC | QNXEPVY TWTWP |
The first seven letters match because both ciphers use the keyword there. From letter eight on, the keys differ and so do the results. The practical effect: Vigenère’s repeating key leaves periodic fingerprints that attacks on Vigenère exploit, while autokey’s non-repeating key removes that specific fingerprint. Other keyed relatives worth comparing are the running key and Gronsfeld ciphers.
Plaintext autokey, ciphertext autokey and a Beaufort-style variant
“Autokey” names a family. The tool above implements the first row only; the other two are shown for comparison and are not available in the tool. Same message (ATTACKATDAWN) and keyword (QUEENLY):
| Variant | Key after the keyword | Rule | Ciphertext |
|---|---|---|---|
| Plaintext autokey (this tool) | plaintext letters | C = P + K | QNXEPVYTWTWP |
| Ciphertext autokey | ciphertext letters | C = P + K | QNXEPVYJQXAC |
| Beaufort-style, plaintext key | plaintext letters | C = K − P | QBLELBYHQTEP |
The first seven letters of the two additive rows match because only the keyword is used there. After that the ciphertext-key row diverges, because its key is built from letters an eavesdropper can already read. A Beaufort-style cipher subtracts the plaintext from the key instead of adding it. If your puzzle says “Beaufort autokey” or “ciphertext autokey”, this tool’s output will not match; check which variant it uses before assuming the keyword is wrong. For the repeating-key relatives see the Beaufort cipher and Vigenère cipher.
What one mistake does to the message
Because decrypted letters feed the key, errors travel. We encrypted THE QUICK BROWN FOX JUMPS with keyword LEMON (5 letters) and tried two kinds of mistake:
- One ciphertext letter altered. Decrypting gave
THE QNICK BYOWN FHX JUMWS. The damaged letters (U→N, R→Y, O→H, P→W) sit exactly 5 letters apart, the keyword length — all the other letters decrypt correctly. - Keyword off by one letter (LEMOX instead of LEMON). Decrypting gave
THE QKICK BBOWN FEX JUMZS. Only every 5th letter is wrong, so the message is still readable.
That is a useful rule of thumb when decoding: text that is almost readable with a repeating gap pattern usually means a near-miss keyword, not the wrong cipher.
Edge cases with the exact output
Each result below was produced by the same encrypt and decrypt functions as the tool above, when this page was built. Text is shown in quotes so spaces stay visible.
Published example: ATTACK AT DAWN with QUEENLY
Encrypt · keyword "QUEENLY"
Input: "ATTACK AT DAWN"
Output: "QNXEPV YT WTWP"
The same keyword and message are used in the Wikipedia article on the autokey cipher, whose ciphertext is QNXEPVYTWTWP. Here the spaces are kept in place, so the letters are the same.
Three-letter keyword: HELLO with KEY
Encrypt · keyword "KEY"
Input: "HELLO"
Output: "RIJSS"
The key is K-E-Y-H-E: the keyword first, then the message letters themselves.
Decrypt with the keyword
Decrypt · keyword "KEY"
Input: "KXRAVD AV NAPQ"
Output: "ATTACK AT DAWN"
Decryption recovers the first letters with the keyword, then uses each recovered letter as key for a later letter.
Mixed case and punctuation
Encrypt · keyword "KEY"
Input: "Attack at Dawn!"
Output: "Kxravd av Napq!"
Letter case and punctuation are kept in place. Punctuation and spaces do not use up key letters; the key is built from letters only.
Keyword with a space, hyphen and digit
Encrypt · keyword "K-E Y 1"
Input: "HELLO"
Output: "RIJSS"
Only the letters A–Z of the keyword are used, so this keyword behaves exactly like KEY.
Keyword longer than the message
Encrypt · keyword "QUEENLY"
Input: "HI"
Output: "XC"
Only the first two keyword letters are needed. None of the message letters ever becomes key, so this case is a plain shift cipher.
An accented letter
Encrypt · keyword "KEY"
Input: "café au lait"
Output: "medé cu qace"
The tool shifts only the unaccented letters A–Z. The accented é is copied unchanged and does not use a key letter.
Not rejected: a keyword with no letters
Encrypt · keyword "123"
Input: "HELLO"
Output: "HELLO"
A keyword with no letters is not an error. The text comes back unchanged, which can look like a successful encryption.
Decrypting with a keyword one letter off
Decrypt · keyword "LEMOX"
Input: "ELQ EHBJO RLWYX GFL FHRDP"
Output: "THE QKICK BBOWN FEX JUMZS"
The ciphertext was made with LEMON. The wrong fifth keyword letter damages every fifth letter, so the text stays almost readable.
Spaces and punctuation never use up key letters. If your own result differs from a worked example, check these three first: the keyword spelling, whether the puzzle uses plaintext or ciphertext autokey, and whether a letter outside A–Z was copied unchanged.
How strong is it, and where did it come from?
It is a puzzle and teaching cipher, not protection. A 3-letter keyword has only 17,576 possibilities and a 5-letter one 11,881,376 — trivial for a computer. Guessed plaintext also gives the key away: subtract a guessed start ATT from the ciphertext K, X, R and you get K, E, Y — the keyword. For solving techniques on related ciphers see frequency analysis and the frequency analysis tool.
Historically, the idea belongs to 16th-century cryptographers; Blaise de Vigenère described a version in his 1586 Traicté des chiffres, and the repeating-key cipher that now carries his name is in fact the simpler one. This tool implements the plaintext-autokey form shown above (not the ciphertext-autokey variant).
Frequently Asked Questions
What is the autokey cipher?
The autokey cipher is a Vigenère-style substitution cipher whose key is not repeated. It starts with a short keyword and then continues the key with the plaintext itself, so the key is as long as the message. Each letter is shifted by the matching key letter, exactly as in Vigenère, with A=0 through Z=25.
How is autokey different from the Vigenère cipher?
Vigenère repeats the keyword (QUEENLYQUEENLY…), while autokey uses the keyword once and then the plaintext (QUEENLYATTACKAT…). The first keyword-length letters of the ciphertext are identical in both; after that they diverge. Because the key never repeats, the repeating-key pattern that Kasiski examination relies on is gone.
How do you decrypt an autokey cipher?
Subtract the keyword from the first ciphertext letters to recover the first plaintext letters. Those recovered letters are the next part of the key, so use them to decrypt the following letters, and keep going. Each decrypted block becomes the key for the block after it. You need the exact keyword to start the chain.
What happens if one letter is wrong?
A single wrong letter damages that position and then every keyword-length position after it, because each wrong plaintext letter becomes a wrong key letter one keyword-length later. With the keyword LEMON (5 letters), one altered ciphertext letter garbled every 5th letter after it. A one-letter typo in the keyword garbles only every 5th letter starting from that keyword position, so the rest of the text stays readable.
Is there an autokey cipher decoder that works without the keyword?
This decoder needs the keyword, because decryption starts by subtracting it from the first ciphertext letters. Without it you need a guess: a guessed start of the message reveals the matching key letters (subtract a guessed ATT from the ciphertext KXR and you get KEY), and a short keyword can be tried exhaustively, since a 3-letter keyword has only 17,576 possibilities.
Does the tool keep spaces, letter case and punctuation?
Yes. Spaces, punctuation and digits stay where they are and do not use up key letters; upper and lower case are kept. Only the letters A–Z are shifted, so an accented letter such as é is copied unchanged. Keyword characters other than A–Z are ignored, and a keyword with no letters leaves the text unchanged rather than raising an error.
What is the difference between plaintext autokey and ciphertext autokey?
Plaintext autokey, which this tool implements, extends the keyword with the message letters. Ciphertext autokey extends it with the ciphertext letters instead. With keyword QUEENLY and message ATTACKATDAWN, plaintext autokey gives QNXEPVYTWTWP and ciphertext autokey gives QNXEPVYJQXAC; the first seven letters agree because both use only the keyword there.
Is the autokey cipher secure?
No. It is stronger than a short repeating Vigenère key, but it is a classical cipher and should not protect real secrets. A short keyword can be brute-forced (a 5-letter keyword has only 11,881,376 possibilities), and a known or guessed piece of plaintext reveals the key letters at that position. Use it for puzzles, teaching and history, not for security.
Features
Privacy Focused
All processing happens in your browser. No data is sent to servers.
Free Forever
No registration, no limits, completely free to use.