Running Key Cipher Tool
Encrypt and decrypt messages with a long non-repeating key text instead of a short repeated keyword.
By Hommer Zhao
TL;DR
- A running key cipher uses a long text as the key stream.
- The key should be at least as long as the alphabetic message.
- It is useful for studying Vigenere-style polyalphabetic ciphers.
- This tool processes text in your browser and preserves formatting by default.
How to Use the Running Key Cipher Tool
- Choose encrypt or decrypt.
- Paste the message into the text box.
- Paste a key passage with at least as many letters as the message.
- Copy the generated output or swap it back into the input for a round trip.
How Running Key Ciphers Work
A running key cipher is a polyalphabetic substitution cipher that uses a long source text as the key. It belongs to the same family as the Vigenere cipher, but it avoids repeating a short keyword across the message.
A running key is a text stream that supplies one key letter for each alphabetic message letter. Convert A-Z to 0-25, add the plaintext and key values modulo 26 to encrypt, and subtract the key value modulo 26 to decrypt.
A one-time pad is a stronger related idea because its key is random, used once, and as long as the message. The difference matters: ordinary book text is not random, so a running key cipher is mainly a historical and educational system rather than modern security. The distinction is summarized in the one-time pad reference.
How it works step by step
- Keep only the letters of the message and number them A = 0 through Z = 25.
- Take the key passage, keep only its letters, and write one key letter under each message letter, starting at the agreed point in the passage. The key continues; it never goes back to the start.
- Encrypt by adding each message value and key value. If the sum is 26 or more, subtract 26 (that is the modulo 26 step). Convert the result back to a letter.
- Decrypt by subtracting the key value from the ciphertext value, adding 26 if the result is negative.
Worked example: ATTACKATDAWN
The message ATTACK AT DAWN has twelve letters, so it uses the first twelve letters of the key passage THE QUICK BROWN FOX: THEQUICKBROW. This is the tool's default example.
| Message | Value | Key | Value | Sum | Cipher |
|---|---|---|---|---|---|
| A | 0 | T | 19 | 19 mod 26 = 19 | T |
| T | 19 | H | 7 | 26 mod 26 = 0 | A |
| T | 19 | E | 4 | 23 mod 26 = 23 | X |
| A | 0 | Q | 16 | 16 mod 26 = 16 | Q |
| C | 2 | U | 20 | 22 mod 26 = 22 | W |
| K | 10 | I | 8 | 18 mod 26 = 18 | S |
| A | 0 | C | 2 | 2 mod 26 = 2 | C |
| T | 19 | K | 10 | 29 mod 26 = 3 | D |
| D | 3 | B | 1 | 4 mod 26 = 4 | E |
| A | 0 | R | 17 | 17 mod 26 = 17 | R |
| W | 22 | O | 14 | 36 mod 26 = 10 | K |
| N | 13 | W | 22 | 35 mod 26 = 9 | J |
The ciphertext is TAXQWSCDERKJ. Note the second row: T (19) plus H (7) is 26, which wraps to 0, so it becomes A. Decrypting reverses each row: for the first letter, T (19) minus T (19) is 0, which is A.
For comparison, the Vigenere cipher with the short keyword QUICK repeated (QUICKQUICKQU) turns the same message into QNBCMAUBFKMH. The key stream is different, but the addition is identical.
A second example, from the Wikipedia article on the running key cipher: the plaintext FLEE AT ONCE with the key text ERRORS CAN O gives JCVSR LQNPS.
Running key vs Vigenere, autokey and one-time pad
| Cipher | Key stream | Repeats? |
|---|---|---|
| Vigenere | A short keyword | Yes, every keyword length |
| Autokey | A short primer, then the message itself | No |
| Running key | A long passage of text, such as a book excerpt | No |
| One-time pad | Random letters, as long as the message, used once | No |
The running key cipher removes the repeating keyword that Vigenere solving methods rely on, but its key is not random. That is the gap between it and a one-time pad. For another text-based system, see the book cipher.
Choosing and sharing the key text
Both people need the same passage and the same starting point. Historically, correspondents agreed on a book in advance and signalled the page and line where the key began, using an indicator inserted into the message. This tool does not create an indicator: you paste the key passage yourself, and it uses the passage from its first letter.
- The key must have at least as many letters as the message.
- Use the same edition and the same starting point on both sides.
- Do not reuse the same key passage for two different messages.
What this tool does
- Only A to Z letters use a key letter. Spaces, digits and punctuation do not.
- The key text is filtered the same way, so spaces and punctuation in it are ignored.
- If the key has fewer letters than the message, the tool shows no output.
- Upper and lower case in the message are kept; the key is read as uppercase.
- With formatting preservation off, the output is shown in groups of five letters.
- Everything runs in your browser; nothing is sent to a server.
Why it is breakable
Both the message and the key are natural-language text, so statistical patterns survive. A single message can also be attacked with a probable word: a guessed fragment of the plaintext is subtracted from every position of the ciphertext, and a position where the result reads like English reveals part of the key (this is described on the running key cipher page). Here is the idea using the ciphertext above and the guessed word ATTACK:
| Position | Ciphertext letters | Key fragment |
|---|---|---|
| 0 | TAXQWSCDERKJ[0..5] | THEQUI |
| 1 | TAXQWSCDERKJ[1..6] | AEXWQS |
| 2 | TAXQWSCDERKJ[2..7] | XXDSAT |
| 3 | TAXQWSCDERKJ[3..8] | QDZCBU |
| 4 | TAXQWSCDERKJ[4..9] | WZJDCH |
| 5 | TAXQWSCDERKJ[5..10] | SJKEPA |
| 6 | TAXQWSCDERKJ[6..11] | CKLRIZ |
Only position 0 gives readable text, THEQUI, which points to the key passage “THE QUI…”. With a longer ciphertext and several guessed words, an attacker can extend this. The same source reports that messages enciphered with the same key can be solved together, and quotes an estimate by Deavours that the unicity distance of a running-key Vigenere cipher in English is eight letters. Unicity distance is a theoretical measure of how much ciphertext leaves a single sensible decryption; it does not say how hard the attack is in practice. Treat the running key cipher as a teaching tool, not as protection for real data.
Short history and use cases
The earliest description of a cipher of this kind is attributed to the French mathematician Arthur Joseph Hermann in 1892, according to the Wikipedia article. A shared book or newspaper column is less conspicuous than a key sheet, which is one reason the idea appeals. It belongs to the wider family of text-based ciphers; see the book cipher overview.
Today it is best used for cryptography lessons, puzzle design, historical demonstrations and comparison with Vigenere, autokey and one-time-pad systems.
Frequently Asked Questions
What is a running key cipher?
A running key cipher is a polyalphabetic substitution cipher that uses a long passage of text, often from a book, as the key stream. Each message letter is combined with the next key letter, so the key does not repeat the way a short Vigenere keyword does.
How is a running key cipher different from the Vigenere cipher?
The arithmetic is the same: add the message letter and key letter modulo 26. The difference is the key. Vigenere repeats a short keyword over the message, while a running key cipher takes its key letters from a long passage that continues for the whole message, so the keyword period that Kasiski examination relies on is gone.
How long does the key text need to be?
At least as many letters as the message. This tool counts only A to Z letters, ignoring spaces, digits and punctuation in both the message and the key, and returns no output if the key has fewer letters than the message.
Is the running key cipher secure?
No, not for protecting real data. Both the message and the key are natural-language text, which leaves statistical patterns, and a guessed word from the message can be tried at every position of the ciphertext to reveal readable key fragments. It is a good cipher for learning, puzzles and historical demonstrations.
How do I decrypt a running key cipher by hand?
Write the same key letters under the ciphertext letters, using the same starting point in the key text. Convert A to Z as 0 to 25 and subtract each key value from the ciphertext value, adding 26 if the result is negative, then convert back to letters.
What should I use as the key text?
Any passage that both sides can obtain and that is at least as long as the message, such as a sentence or a book excerpt. Both sides must start at the same point in it. Historically, the sender and receiver agreed on a book beforehand and indicated the starting page and line; this tool does not generate that indicator, you paste the key passage yourself.