On this page
A Caesar cipher shifts every letter by the same amount, so counting letters cracks it. The Vigenère cipher changes the shift letter by letter using a keyword. Below you will encrypt a message by hand, see why letter counting fails, and break it with Kasiski's method.
What is the Vigenère cipher?
The Vigenère cipher encrypts each letter of the message with a different Caesar shift, chosen by the letters of a repeating keyword (Wikipedia: Vigenère cipher). It was first described by Giovan Battista Bellaso in 1553 and only in the 19th century misattributed to Blaise de Vigenère, which is how it got its name (same source).
Number the letters A = 0, B = 1, up to Z = 25. If M is a message letter and K is the key letter above it, the cipher letter is C = (M + K) mod 26, and decryption is M = (C − K) mod 26 (same source).
How do you encrypt a message by hand?
Take the message THE CAT AND THE DOG SAW THE OWL and the keyword SUN (S = 18, U = 20, N = 13).
Remove spaces: THECATANDTHEDOGSAWTHEOWL (24 letters).
Write SUNSUNSUN… under it, one key letter per message letter.
Add each pair mod 26. T (19) + S (18) = 37, and 37 − 26 = 11, which is L. H (7) + U (20) = 27, which is 1, or B.
Carry on to the end. The ciphertext is LBRUUGSHQLBRVITKUJLBRGQY.
Why did frequency analysis fail for three centuries?
In a Caesar cipher each plaintext letter always becomes the same cipher letter; Vigenère cuts that link. In our example the T of THE becomes L but the T of CAT becomes G, and cipher U comes from both C and A, so letter counts flatten out.
That earned the cipher the name le chiffre indéchiffrable, the indecipherable cipher. No general method of breaking it was published until 1863, three centuries after Bellaso (Wikipedia: Vigenère cipher). Charles Babbage broke a variant as early as 1854 but did not publish his work (same source).
How does the Kasiski examination find the key length?
Friedrich Kasiski was the first to publish a general attack, in 1863, in his book Die Geheimschriften und die Dechiffrir-Kunst (Wikipedia: Kasiski examination). If the same plaintext word falls under the same part of the keyword twice, it becomes the same ciphertext twice, and that happens only when the gap is a multiple of the key length.
So you find repeated strings of three or more letters, measure their distances, and take the greatest common divisor, which gives the key length or a multiple of it (same source); our post on Euclid's gcd algorithm, step by step shows how. Some repeats are coincidence, so one odd distance should not overrule several that agree (same source).
What does the index of coincidence add?
The index of coincidence is the chance that two letters picked at random from a text are the same letter, a measure William F. Friedman set out in 1922 (Wikipedia: Index of coincidence). For English it is about 0.067, while for text where every letter is equally likely it is 1/26, about 0.0385 (same source).
To test a guessed key length L, write the ciphertext in L columns and compute each column's index. If L is right, each column is a plain Caesar cipher and looks like English; if wrong, the index drops towards 0.0385. In Wikipedia's worked example, the normalised index is 1.82 for the true key length 5 and 2.07 for 10, a multiple of 5, against 0.99 to 1.19 for the other guesses (same source).
A worked break: can you crack LBRUUGSHQLBRVITKUJLBRGQY?
Find repeats. LBR appears at positions 1, 10 and 19.
Measure distances. 10 − 1 = 9 and 19 − 10 = 9. The gcd is 9, so the key length is 1, 3 or 9. Length 1 would be a plain Caesar cipher, so try 3 first.
Guess a probable word. A fragment that repeats three times is likely THE. Assume LBR = THE.
Subtract. L − T = 11 − 19 = −8, which is 18 mod 26, or S. B − H = 1 − 7 = −6, which is 20, or U. R − E = 17 − 4 = 13, or N. The key is SUN.
Check. Decrypt the next block, UUG, with SUN: U − S = C, U − U = A, G − N = T. CAT makes sense, so the key is right.
In a message this short the guess in step 3 does the work. On a longer ciphertext you would confirm the length with the index of coincidence, then match each column's letter counts against English to read off each key letter.
Every step above is modular arithmetic and a gcd. If either feels shaky, the Fermi Concept Library gives each concept in mathematics and computing its own lesson and its place in the map. Next, see how computers handle huge powers in modular exponentiation by square and multiply.



