The running-key cipher is a polyalphabetic substitution cipher that works like the Vigenère cipher but takes its key from a long stretch of text — classically a passage from an agreed book — rather than repeating a short keyword. Because the key is as long as the message and never repeats, it removes the periodic structure that makes ordinary Vigenère vulnerable to Kasiski analysis.
How it works
Letters are numbered 0 (A) through 25 (Z). The letters of the key passage are lined up beneath the message, one key letter per message letter. Encryption adds them modulo 26:
C = (P + K) mod 26
Decryption subtracts the same key letters:
P = (C - K) mod 26
Only letters in the key passage are used; its spaces and punctuation are skipped. In the message, non-letter characters pass through unchanged and do not consume a key letter, so the alignment between message letters and key letters is preserved.
Example
With key passage KING and plaintext MEET:
P: M E E T
K: K I N G
C: W M R Z
M (12) plus K (10) is 22 → W, and so on. Decrypting WMRZ with the same key KING subtracts each key letter to recover MEET.
Notes
- The key passage must supply at least as many letters as the message; if it is too short, the trailing letters of the message are left in the clear.
- The running-key cipher is not a one-time pad: natural-language key text is highly redundant, so the cipher is breakable by methods that play the statistics of the message against those of the key.
- Sender and receiver must agree on the exact same source text and starting point — including how punctuation is handled — or decryption drifts out of alignment.