The Vigenère Cipher, Explained
After reading this you will be able to encrypt and decrypt with the Vigenère cipher by hand, understand why it defeats simple frequency analysis, and see exactly how it is broken by finding the key length and solving each column as a Caesar shift.
What the Vigenère cipher is
The Vigenère cipher shifts each letter of your message by an amount that depends on a repeating keyword. It is a polyalphabetic cipher: instead of one fixed alphabet mapping, it cycles through many shifted alphabets. That single change defeats the letter-counting attack that breaks the Caesar and simple substitution ciphers.
Here is the hook. Take the plaintext ATTACKATDAWN and the key LEMON. The key repeats to line up under the plaintext: LEMONLEMONLE. Each plaintext letter is shifted forward by the position of the key letter in the alphabet (L is 11, E is 4, M is 12, and so on). The result is LXFOPVEFRNHR.
Notice the two Ts at positions 2 and 3 of the plaintext become X and F. The same plaintext letter produced two different ciphertext letters, because it sat under two different key letters. That is the whole point, and it is why the cipher resisted cryptanalysis for about three centuries and earned the nickname le chiffre indéchiffrable, the indecipherable cipher.
When to use it, and when not
Use Vigenère for teaching, puzzles, escape rooms, and any setting where the goal is to understand classical cryptography or to have fun. It is a clean illustration of the leap from monoalphabetic to polyalphabetic encryption.
Do not use Vigenère to protect anything real. It was broken publicly by Friedrich Kasiski in 1863 and by Charles Babbage a decade earlier. A short repeating key leaks its length, and once the length is known each column collapses to a Caesar cipher that a computer solves in milliseconds. For actual confidentiality, use a standard authenticated cipher such as AES-GCM (NIST SP 800-38D).
The one variant with a real security proof is the one-time pad: a key as long as the message, chosen uniformly at random, never reused. Vigenère with a short repeating key is not that, and the repetition is exactly what kills it.
The formula and the intuition
Number the letters A to Z as 0 to 25. Let p_i be the value of the plaintext letter at position i, and let k_i be the value of the key letter aligned with it. Encryption is:
Here c_i is the ciphertext value, p_i the plaintext value, and k_i the key value at position i. The key repeats, so if the key has length m then k_i = key_{(i \bmod m)}. Decryption reverses the shift:
The intuition: each key letter selects one of 26 Caesar alphabets. Key letter A (value 0) shifts by nothing, key letter B shifts by 1, up to key letter Z which shifts by 25. Vigenère is simply a Caesar cipher whose shift changes every letter according to the key. When the key has length 1, it is a Caesar cipher. See the Caesar Cipher and ROT tool for that special case, and the Substitution, Atbash and Affine tool for the monoalphabetic ciphers Vigenère improves on.
A worked example with LEMON
Encrypting ATTACKATDAWN with the key LEMON
- Write the plaintext values: A=0, T=19, T=19, A=0, C=2, K=10, A=0, T=19, D=3, A=0, W=22, N=13.
- Repeat the key LEMON to length 12 and write its values: L=11, E=4, M=12, O=14, N=13, then repeat: L=11, E=4, M=12, O=14, N=13, L=11, E=4.
- Add each pair mod 26. Position 0: (0 + 11) \bmod 26 = 11 which is L.
- Position 1: (19 + 4) \bmod 26 = 23 which is X.
- Position 2: (19 + 12) \bmod 26 = 31 \bmod 26 = 5 which is F. The wrap-around at 26 is what turns the second T into a different letter than the first.
- Continuing through all twelve positions gives
LXFOPVEFRNHR.
The table below shows the full alignment. Read it top to bottom, column by column.
| Position | Plain | p value | Key | k value | Cipher |
|---|---|---|---|---|---|
| 0 | A | 0 | L | 11 | L |
| 1 | T | 19 | E | 4 | X |
| 2 | T | 19 | M | 12 | F |
| 3 | A | 0 | O | 14 | O |
| 4 | C | 2 | N | 13 | P |
| 5 | K | 10 | L | 11 | V |
To decrypt, subtract instead of add. Position 2: (5 - 12) \bmod 26 = -7 \bmod 26 = 19, which is T. The modulo keeps negative results in range, so always add 26 before taking the remainder if your calculator returns a negative number.
Why it beats frequency analysis
In English, the letter E appears about 12.7% of the time and Z about 0.07%. A monoalphabetic cipher preserves those frequencies: whatever E maps to also appears about 12.7% of the time, so counting letters cracks it. Vigenère spreads each plaintext letter across up to m different ciphertext letters, flattening the frequency histogram.
A useful number here is the index of coincidence (IC), the probability that two randomly chosen letters of a text are equal. For natural English it is about 0.0667. For uniformly random letters it is 1/26 \approx 0.0385. Vigenère pushes the ciphertext IC toward that random floor as the key gets longer, and that behavior is exactly what an attacker measures to find the key length.
How it is broken: key length then columns
The attack has two stages. First find the key length m. Second, split the ciphertext into m columns and solve each as a Caesar cipher.
- Kasiski examination
- Find repeated substrings in the ciphertext and measure the distances between them. Repeats often arise when the same plaintext lines up with the same key. The key length divides most of those distances, so the greatest common divisor of the gaps suggests m.
- Index of coincidence test
- Assume a key length, split the text into that many columns, and average each column's IC. When the guessed length is correct, each column is a Caesar shift of English text, so its IC jumps back up near
0.0667. Wrong guesses stay near0.0385.
Once m is known, column j holds every plaintext letter that sat under key position j. All of them share one shift, so each column is an independent Caesar cipher. Solve 5 small Caesar puzzles instead of one Vigenère, and the key falls out. A computer tries all 26 shifts per column and scores each against English frequencies.
Common mistakes
Three errors trip up people doing Vigenère by hand or reading its output.
- Miscounting letter values. A is 0, not 1. If you use 1 to 26 your shifts are off by one and nothing decrypts. Keep A at 0 so the modulo arithmetic works.
- Letting non-letters shift the key. Decide whether spaces and punctuation advance the key. Most implementations, including this tool, skip non-letters and keep the key position fixed across them. If you and your correspondent disagree on this rule, the decrypt drifts out of sync after the first space.
- Reusing a short key on long text. The shorter the key relative to the message, the more repeats an attacker finds. A 3-letter key on a 3000-letter message is trivial to break. Key length is the security parameter, and even a long non-random key (a phrase) is far weaker than random letters.
To sanity-check any Vigenère result, encrypt a short known string like ATTACKATDAWN with LEMON and confirm you get LXFOPVEFRNHR. If that matches, your value scheme and modulo are correct.
Related tools
Vigenère sits between two families. When the key has length 1 it reduces to a single shift, which the Caesar Cipher and ROT tool handles directly, including brute-forcing all 26 shifts. If you want a fixed one-to-one letter mapping instead of shifts, the Substitution, Atbash and Affine tool covers the monoalphabetic ciphers. For a completely different classical encoding that is about signaling rather than secrecy, see the Morse Code Translator.
Frequently asked questions
Is the Vigenère cipher secure?
No. It resisted attack until the 1800s, but Kasiski examination and the index of coincidence break any repeating-key Vigenère. Treat it as educational, not protective.
What is the difference between Vigenère and a one-time pad?
Both add a key to the plaintext mod 26. The one-time pad uses a truly random key as long as the message, used only once, which makes it unbreakable. Vigenère repeats a short key, and that repetition is precisely the weakness that reveals the key length.
Does case or punctuation matter?
The cipher works on the 26 letters only. This tool preserves case for readability and skips non-letter characters without advancing the key. Numbers, spaces, and punctuation pass through unchanged.
How long should the key be?
For any real security, as long as the message and random, which turns it into a one-time pad. For puzzles, longer keys are harder to crack than short ones, but no repeating key is safe against a computer.
Why did the two T's in ATTACK become different letters?
They were shifted by different key letters. The first T sat under E (shift 4) and became X; the second T sat under M (shift 12) and became F. Different shifts on the same input give different outputs, which is what defeats simple frequency analysis.