classical · level 2

Vigenère Cipher

A repeating key defeats simple frequency analysis.

150 XP

Vigenère Cipher

Blaise de Vigenère published a polyalphabetic cipher in 1586 that stumped cryptanalysts for nearly three centuries. It was called le chiffre indéchiffrable — the indecipherable cipher. By the 1860s two independent techniques had cracked it.

Analogy

Imagine a relay line of translators, each speaking a slightly different dialect. You hand the first translator one word, the second translator the next word, and so on — when you reach the end of the line, the next word goes back to the first translator. Because the pattern repeats with a fixed rhythm, a listener can't just count common vowels to crack it; they have to figure out how many translators there are, then listen to each translator's output separately. That's Vigenère, and figuring out the line's length is exactly what the Kasiski method does.

The key table

Vigenère uses a repeating keyword. For each letter of the plaintext, you use the corresponding keyword letter as the shift:

Plaintext:  A T T A C K A T D A W N
Key:        L E M O N L E M O N L E
Shift:      11 4 12 14 13 11 4 12 14 13 11 4
Ciphertext: L X F O P V E F R N H R

Encryption: C[i] = (P[i] + K[i mod len(key)]) mod 26
Decryption: P[i] = (C[i] − K[i mod len(key)] + 26) mod 26

Why it defeated simple frequency analysis

A single Caesar shift maps every E to the same ciphertext letter. Vigenère maps E to a different letter depending on which position in the key governs it. With a 5-letter key, each ciphertext letter could represent any of 5 different plaintext letters. Frequency counts of the full ciphertext are nearly flat — the signal is hidden.

Why Kasiski broke it

Charles Babbage (1846) and Friedrich Kasiski (1863) noticed that if the same plaintext trigram appears at positions that are multiples of the key length apart, it will encrypt to the same ciphertext trigram. Finding repeated trigrams reveals likely key-length factors.

Kasiski examination:

  1. Search for repeated sequences of 3+ letters in the ciphertext.
  2. Record the spacing between each pair.
  3. The key length is a common factor of those spacings.

The Index of Coincidence

Even without repeated sequences, the Index of Coincidence (IC) estimates key length. The IC of a text is the probability that two randomly chosen letters are the same:

IC = Σ fᵢ(fᵢ − 1) / (n(n − 1))

Random text has IC ≈ 0.038. English has IC ≈ 0.065. If you split the ciphertext into every kth letter (one "column" per key position), each column is a Caesar cipher. When k equals the true key length, each column's IC should be close to 0.065.

The Vigenère tableau

The tableau is a 26×26 grid. Row i is the alphabet shifted left by i. To encrypt: find the row indexed by the key letter, then the column indexed by the plaintext letter. The cell is the ciphertext letter.

Playground

Type plaintext and a keyword to encrypt. Edit the keyword and watch each letter shift differently. Decrypt by toggling the mode switch.

Visualizer

The active row of the Vigenère tableau is highlighted as you type. Each input character selects the row corresponding to the current key letter, then highlights the column of the plaintext letter, showing the ciphertext at the intersection.