Introduction
The Vigenere cipher has a well-known weakness: if the key is shorter than the plaintext, it repeats, and the repetition creates patterns that Kasiski examination and frequency analysis can exploit. Two historical variants tried to fix this. The autokey cipher extends the key with plaintext characters after the initial keyword is exhausted. The running key cipher uses a long text (a book passage, a newspaper article) as the key so it never repeats. This tool encrypts and decrypts with both methods side by side, showing exactly where their keystreams diverge and how the choice of key extension affects the ciphertext. All computation runs in your browser.
What this tool does
- Encrypt and decrypt with the autokey cipher, where the key stream is the user's keyword followed by the plaintext itself
- Encrypt and decrypt with the running key cipher, where the key stream is the user's keyword repeated cyclically to match the plaintext length
- Display both ciphertexts side by side with their extended key streams, so you can see exactly where the two methods diverge
- Show a step-by-step encryption table with per-character input, key character, and output values (0-based alphabet positions) for both ciphers
- Indicate the divergence point where the autokey key stream switches from the keyword to plaintext characters, and the running key cycles back to the start
- Process only A-Z letters; non-alphabetic characters pass through unchanged
How this tool works
The tool implements both ciphers in pure TypeScript. Both use the standard Vigenere formula: `C = (P + K) mod 26` for encryption and `P = (C - K) mod 26` for decryption, where P is the plaintext letter position (0-25), K is the key letter position, and C is the ciphertext letter position.
The autokey cipher builds its key stream as follows: the user's keyword comes first. Once the keyword is exhausted, each subsequent key character is taken from the plaintext itself. So for keyword `LEMON` and plaintext `ATTACKATDAWN`, the key stream is `LEMON` followed by `ATTAC` (the first 5 plaintext characters), giving `LEMONATTAC`. During decryption, the key stream is rebuilt from the keyword plus the already-decrypted plaintext, which means the decryptor can reconstruct the key as they go.
The running key cipher simply repeats the keyword cyclically. For keyword `LEMON` and plaintext `ATTACKATDAWN`, the key stream is `LEMONLEMONLE`. This is the classic Vigenere behavior. If the keyword is short relative to the plaintext, the same key characters encrypt multiple positions, creating the repetition patterns that Kasiski examination detects.
The tool shows both extended key streams and highlights the divergence point: the position where the autokey stream switches from keyword to plaintext characters. Before that point, both ciphers produce identical output. After it, they diverge completely. The step-by-step table shows the numeric values for each character position, making the modular arithmetic visible.
How autokey and running key ciphers work
The Vigenere cipher was first described by Giovan Battista Bellaso in 1553, though it was later misattributed to Blaise de Vigenere in the 19th century. The autokey variant was described by Vigenere himself in 1586 in his work 'Traicte des Chiffres.' The running key cipher is essentially the standard Vigenere with a long key, and was analyzed extensively in Helen Fouche Gaines's book Cryptanalysis (1939), which remains a standard reference for classical cipher techniques.
The autokey cipher's security improvement comes from the fact that the key stream does not repeat. After the initial keyword, each key character depends on the plaintext, so the period of the key stream equals the plaintext length. This defeats Kasiski examination, which relies on finding repeated sequences in the ciphertext that correspond to repeated key segments. However, the autokey has its own weakness: each key character after the keyword is a plaintext character, so if an attacker recovers one plaintext character beyond the keyword length, they can derive the corresponding key character and use it to decrypt the next position, creating a chain.
The running key cipher avoids repetition by using a key that is as long as the plaintext. Historically, the key was a passage from a book, a newspaper article, or any text known to both sender and receiver. The security depends on the key text being unpredictable to an attacker. If the attacker knows or can guess the source text, the cipher is broken. Gaines describes techniques for cryptanalyzing running key ciphers in her book, including methods that exploit the statistical properties of natural language in the key text.
Both ciphers operate on the 26-letter English alphabet. The tool processes only A-Z characters (case-insensitive, converted to uppercase) and passes all other characters through unchanged. This matches the historical behavior of these ciphers, which were designed for alphabetic text.
How to use this tool
- Enter a keyword in the Key field. Both ciphers use this as the initial key segment
- Select Encrypt or Decrypt mode using the toggle buttons
- Type or paste your plaintext (for encryption) or ciphertext (for decryption) in the input field
- Compare the two results in the side-by-side panel: autokey on the left, running key on the right, each showing its extended key stream and output
- Check the keystream comparison in the output to see where the two key streams diverge (after the keyword is exhausted)
- Expand the step-by-step table to see per-character input, key, and output values with their 0-based alphabet positions
Real-world examples
Encrypting 'ATTACKATDAWN' with key 'LEMON'
Plaintext: `ATTACKATDAWN` (12 letters). Keyword: `LEMON` (5 letters). The autokey key stream is `LEMON` + `ATTAC` (first 5 plaintext chars) = `LEMONATTAC` + `K` (6th plaintext char) = `LEMONATTACKA` (12 chars). The running key stream is `LEMON` repeated: `LEMONLEMONLE`. Both produce identical ciphertext for the first 5 characters (LXFOPVEFRNHR). At position 6, they diverge: autokey uses plaintext 'A' (position 0) as the key, while running key cycles back to 'L' (position 11). The divergence point is position 5 (0-indexed).
Short plaintext (shorter than the key)
Plaintext: `HI` (2 letters). Keyword: `LEMON` (5 letters). Since the plaintext is shorter than the keyword, both ciphers use only the first 2 characters of the keyword (`LE`) as the key stream. The autokey never reaches the point where it extends with plaintext, and the running key never cycles. Both produce identical ciphertext: `SM`. The output notes that 'Keys are identical (input shorter than or equal to key length).'
Decrypting autokey ciphertext
Ciphertext: `LXFOPVEFRNHR` with keyword `LEMON`. The tool decrypts the first 5 characters using the keyword, recovering `ATTAC`. It then uses these recovered plaintext characters as the key for positions 6-10, recovering `KATDA`. Finally, it uses the recovered 'K' as the key for position 12, recovering 'W'. The full plaintext is `ATTACKATDAWN`. This chain-like decryption is what makes the autokey cipher both interesting and vulnerable: each recovered character feeds into the next key position.
Long plaintext with a short key
Plaintext: `THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG` (35 letters). Keyword: `KEY` (3 letters). The running key stream is `KEY` repeated 12 times: `KEYKEYKEYKEY...`. This creates a period-3 repetition that Kasiski examination can detect by finding repeated trigrams in the ciphertext spaced 3 apart. The autokey key stream is `KEY` + the first 32 plaintext characters, giving a non-repeating stream of length 35. The autokey is significantly harder to break with classical methods because there is no repetition to exploit.
Non-alphabetic characters in input
Plaintext: `ATTACK AT DAWN!` with keyword `LEMON`. The spaces and exclamation mark are not A-Z letters, so they pass through unchanged. Only the alphabetic characters are encrypted. The autokey key stream is built only from alphabetic characters: `LEMON` + `ATTACKATDAWN`. The output preserves the spaces and punctuation in their original positions: `LXFOP VE FRNHR!`.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| Autokey cipher | Key extends with plaintext, non-repeating | Historical cipher, harder to break than Vigenere |
| Running key cipher | Key repeated cyclically, period = key length | Standard Vigenere with short key, vulnerable to Kasiski |
| Vigenere (long key) | Key as long as plaintext, non-repeating | Secure if key is random and used once (one-time pad) |
| One-time pad | Random key, same length as plaintext, used once | Information-theoretically secure (Shannon, 1949) |
| Standard Vigenere | Short keyword repeated, period = keyword length | Educational, trivially broken with Kasiski + frequency analysis |
Limitations or considerations
Both the autokey and running key ciphers are classical polyalphabetic ciphers and are not secure by modern standards. They can be broken with computational cryptanalysis, and even by hand using the techniques described in Gaines's 'Cryptanalysis' (1939).
The autokey cipher's key stream depends on the plaintext, which creates a vulnerability: if an attacker correctly guesses a plaintext character beyond the keyword length, they can derive the key character for the next position and chain forward. This is described in detail in classical cryptanalysis texts. The autokey is harder to break than standard Vigenere but is not secure against determined analysis.
The running key cipher is vulnerable if the key text is known or can be guessed. If the key is a passage from a published book, an attacker who suspects the source can try known texts. Even without knowing the source, statistical methods that exploit the non-uniform distribution of letters in natural language can reduce the search space.
This tool processes only A-Z letters (uppercase). Lowercase input is converted to uppercase. All other characters (digits, punctuation, spaces, Unicode) pass through unchanged and are not counted in the key stream. This means the effective key length may differ from the total input length.
For breaking Vigenere-family ciphers, use the Vigenere Cracker tool. For the standard Vigenere cipher, see Vigenere Cipher. For the autokey cipher alone, see Autokey Cipher. For the running key cipher alone, see Running Key Cipher.
Frequently asked questions
What is the difference between autokey and running key ciphers?
The autokey cipher extends the key stream with plaintext characters after the initial keyword is exhausted. The running key cipher repeats the keyword cyclically to match the plaintext length. Both use the same Vigenere formula (C = P + K mod 26), but the autokey produces a non-repeating key stream while the running key repeats with a period equal to the keyword length.
Why is the autokey cipher harder to break than standard Vigenere?
The autokey key stream does not repeat, so Kasiski examination (which detects repeated ciphertext segments caused by key repetition) does not work. However, the autokey has a different weakness: each key character after the keyword is a plaintext character, so recovering one plaintext character lets an attacker derive the next key character and chain forward. This makes it harder to break than standard Vigenere but not truly secure.
Who invented the autokey cipher?
The autokey cipher was described by Blaise de Vigenere in 1586 in his work 'Traicte des Chiffres.' The underlying Vigenere cipher was actually first described by Giovan Battista Bellaso in 1553, but was later misattributed to Vigenere. The autokey variant was Vigenere's own contribution to the family.
What is a running key and how is it chosen?
A running key is a key text that is as long as the plaintext, typically drawn from a book, newspaper, or other shared text. The sender and receiver agree on the source text in advance. The security depends on the key text being unpredictable. Historically, parties used specific pages from agreed-upon books. If an attacker knows the book, the cipher is broken.
Can these ciphers be broken automatically?
Yes. The running key cipher (which is standard Vigenere with a repeated short key) can be broken with the Vigenere Cracker tool, which uses Kasiski examination and frequency analysis. The autokey cipher requires different techniques but can also be broken computationally. Helen Fouche Gaines describes hand methods for both in her 1939 book 'Cryptanalysis.'
What happens with non-alphabetic characters?
Both ciphers process only A-Z letters. Lowercase letters are converted to uppercase. Spaces, digits, punctuation, and other characters pass through the cipher unchanged and are not included in the key stream. This matches the historical design of these ciphers, which were created for alphabetic text.
Conclusion
The autokey and running key ciphers represent two historical attempts to fix the Vigenere cipher's key repetition problem. The autokey extends the key with plaintext, creating a non-repeating stream but introducing a chain dependency. The running key uses a long text to avoid repetition but depends on the key text being secret. This tool shows both methods side by side so you can see exactly how their keystreams diverge. For the standard Vigenere Cipher, the Autokey Cipher alone, or the Running Key Cipher alone, use the dedicated tools. To break Vigenere-family ciphers, try the Vigenere Cracker.