The Vigenère Cipher Explained: Keyword Encryption That Held for 300 Years
How the Vigenère cipher uses a keyword and modular shifts to beat frequency analysis, with a worked LEMON example, plus why it loses every CTF to Kasiski.
The Vigenère Cipher Explained: Keyword Encryption That Held for 300 Years
For most of the history of secret writing, a simple substitution cipher was good enough to fool an enemy and useless against a patient codebreaker. Shift every letter by three, and you have a Caesar cipher that a child can crack by counting how often each symbol shows up. The Vigenère cipher broke that pattern. By rotating through many shifts instead of one, it earned the nickname le chiffre indéchiffrable — the indecipherable cipher — and kept it for roughly three centuries.
It is not secure anymore, and it never should be trusted with anything that matters. But it is one of the cleanest ways to understand why "use a key" changed everything in cryptography, and it remains a fixture in puzzles, escape rooms, and capture-the-flag competitions. Here is how it actually works.
One Shift Versus Many
A Caesar cipher applies a single fixed shift to the whole message. Pick 3, and every A becomes D, every B becomes E, and so on. The fatal weakness is that the letter frequencies survive the shift untouched. English text leans heavily on E, then T, A, O. Whatever the most common ciphertext letter is, that is almost certainly your shifted E, and the rest tumbles out from there.
The Vigenère cipher refuses to use one shift. Instead it takes a keyword, repeats it across the length of your message, and uses each keyword letter to pick a different Caesar shift for the letter sitting underneath it. The same plaintext letter no longer maps to the same ciphertext letter — it depends entirely on where it lands in the message. That moving target is what the word polyalphabetic describes, and it is exactly what flattens the frequency signal a cryptanalyst would otherwise pounce on.
The Math: One Modular Addition Per Letter
The whole cipher reduces to a single rule. Number the alphabet so that A=0, B=1, all the way to Z=25. For each letter, take the plaintext value, add the value of the current keyword letter, and wrap around the alphabet with mod 26:
ciphertext = (plaintext + key) mod 26 (per letter)
Decryption runs the same line in reverse — subtract instead of add:
plaintext = (ciphertext - key + 26) mod 26
The + 26 just keeps the result positive before the modulo, since subtracting a large key value can dip below zero. That is the entire algorithm. There is no table you strictly need to memorize; the famous Vigenère square (a 26×26 grid of shifted alphabets) is only a lookup chart for this one addition.
A Worked Example With the Keyword LEMON
The textbook vector is ATTACKATDAWN encrypted with the keyword LEMON. First, repeat the keyword to match the message length:
Plaintext: A T T A C K A T D A W N
Keyword: L E M O N L E M O N L E
Now apply (plaintext + key) mod 26 to each column. Take the first pair: A is 0, L is 11, so 0 + 11 = 11, which is L. The second pair: T is 19, E is 4, so 19 + 4 = 23, which is X. Keep going:
A+L = 0+11 = 11 -> L
T+E = 19+4 = 23 -> X
T+M = 19+12 = 31 mod 26 = 5 -> F
A+O = 0+14 = 14 -> O
C+N = 2+13 = 15 -> P
K+L = 10+11 = 21 -> V
A+E = 0+4 = 4 -> E
T+M = 19+12 = 31 mod 26 = 5 -> F
D+O = 3+14 = 17 -> R
A+N = 0+13 = 13 -> N
W+L = 22+11 = 33 mod 26 = 7 -> H
N+E = 13+4 = 17 -> R
The ciphertext is LXFOPVEFRNHR. Notice the two T's in ATTACK became X and F — different letters from the same plaintext, because they sat over different keyword letters. That single property is the reason frequency analysis stalls. Feed LXFOPVEFRNHR back in with mode set to Decrypt and the same keyword, and you get ATTACKATDAWN again. You can watch this play out, with each keyword letter lined up against the character it shifts, in the Vigenère cipher encoder and decoder.
One detail matters in practice: spaces, digits, punctuation, and non-Latin characters should pass straight through without consuming a keyword position. If a comma advanced the key pointer, the running key would drift out of step with the actual letters and decryption would return garbage. Every standard test vector assumes the cipher only steps the key on real letters, which is why this is the default behavior to expect from any correct implementation.
Why It Held, and Why It Eventually Fell
I first met this cipher as a CTF challenge years ago: a wall of uppercase ciphertext, a single hint that the key was a song title, and no idea where to start. What struck me was how much harder it felt than the Caesar ciphers I had already breezed through. With Caesar there are only 25 possibilities — you try them all in under a minute. With Vigenère, the number of keys explodes with the keyword length, and naive frequency counting simply does not bite. I burned an hour guessing band names before I learned there was a method.
That method is the Kasiski examination, published by Friedrich Kasiski in 1863, later sharpened by William Friedman's index-of-coincidence test. The trick is that a repeating keyword leaves a fingerprint: when a common word in the plaintext happens to line up with the same stretch of keyword more than once, identical chunks appear in the ciphertext. Measure the distances between those repeats, find their common factors, and you recover the keyword length. Once you know the length, the cipher collapses — you split the ciphertext into separate columns that each used one fixed shift, and every column is just a Caesar cipher you crack with the frequency analysis the cipher was supposed to defeat. Three centuries of reputation, undone by spotting repeated patterns.
Where It Still Belongs
So no, do not protect anything real with it. For genuine confidentiality you want modern, key-derived encryption — the kind of authenticated scheme you would reach for in an AES text encryptor, not a 16th-century letter shuffle. Vigenère's value now is pedagogical and recreational.
It is the perfect bridge for teaching how keys defeat frequency analysis, because students can type the LEMON example, watch the running key march along, and see why the same letter encrypts two different ways. It is a reliable CTF and puzzle staple, where the challenge is usually finding the key length and then the key. And it is a fine, reversible obfuscation for low-stakes fun: a scavenger-hunt clue, an escape-room note, an inside joke that anyone holding the shared keyword can read and anyone else sees as noise. Treat it as a beautiful piece of cryptographic history that you can still play with by hand — and let AES handle the secrets that count.
Made by Toolora · Updated 2026-06-13