Lesson
The theory — Vigenère Cipher: Find the Key Length, Then Break It
The Vigenère cipher adds a repeating key to the message letter by letter. With A = 0 to Z = 25, cipher letter i is (message letter i + key letter i mod L) mod 26, so each key letter is a Caesar shift applied to every L-th letter. The index of coincidence of N letters, IC = Σ n(n − 1) / (N(N − 1)), is the chance that two letters taken from different places are the same: 1/26 = 0.0385 for random letters, about 0.066 for English. Friedman's test writes the ciphertext in rows of k and counts coincidences down the columns: at the key length, and at its multiples, every column is shifted English and its IC returns to English's. Kasiski's test, published in 1863, factors the spacings between repeated groups of letters.
What each symbol means
L- the number of letters in the key
k- a key length being tried: the number of columns the ciphertext is dealt into
N- the number of letters in the message
n- in the IC formula, how many times one letter occurs
- Assumes
- Letters only: case, spaces and punctuation are dropped before encrypting, as on Carroll's card. “English” here means Chapter I of Alice's Adventures in Wonderland, 8,606 letters; its letter shares and its IC of 0.0665 are the reference for every test, and the trials that measure success draw their messages from the same chapter, which flatters the attack slightly. The key length is the smallest k whose average column IC is at least three quarters of the way from 1/26 to English. Random keys draw each letter uniformly, so their letters may repeat, and a key whose letters repeat at half its length can lift the bar at half the length over the line.
Problem solved in full
-
Was Carroll's cipher card right? 4 steps
Lewis Carroll had a card printed explaining this cipher. It is undated; his letters about sending a key-word are from April 1868, five years after Kasiski's book. The card encrypts “meet me on Tuesday evening at seven” under the key-word vigilance and promises that it will be “impossible for any one, ignorant of the key-word, to decipher the message, even with the help of the table.” Press Carroll's card: can the page read his message? Then encrypt the opening of Chapter I under the same key-word. How many letters does the page need to read VIGILANCE back?
-
Check one letter by hand. m is 12 and v is 21; 12 + 21 = 33, and 33 − 26 = 7, which is h. The page's ciphertext, HMKBXEBPXPMYLLYRXIIQTOLTFGZZV, is Carroll's letter for letter.
-
29 letters in 9 columns gives two columns of 4 and seven of 3. No three-letter group repeats, so Kasiski has nothing to factor. No bar reaches the line at 0.0595; the tallest is k = 9, at 0.0556, so the length comes out right. Chi-squared over three or four letters is close to a guess, though: the key comes back as HIGXXLNPM, with 3 of its 9 letters right, and 10 of the 29 message letters.
-
Press VIGILANCE, 189 letters: the chapter's opening under Carroll's key-word, 21 letters a column. Bar 9 is the first over the line, at 0.0794, and 4 of the 5 spacings between repeated groups are multiples of 9 (54, 36, 27 and 72; the fifth is 29). All nine columns come out right, and so do all 189 letters.
-
Set the letters to 188. The length is still 9, but column 9 now has 20 letters and fits T better than E: 168 of 188 letters come back. The 189th letter falls in column 9 and tips it to E.
Answer
On the page, Carroll's own message holds and 189 letters of Alice do not. Three or four letters a column is too few to count, and the key comes back as HIGXXLNPM; 21 letters a column are enough to read VIGILANCE back. What protected his message was its length. Whether someone who guessed one of its words, “Tuesday” say, could read the rest, the page cannot test: it only counts letters.
-
Learning path
How codes are broken
References (3)
- The two ends of the bar chart in the first insight (.066 for a correct period, .038 for a wrong one), and the method itself: write the ciphertext in lines of the assumed period and count coincidences down the columns, for each assumption in turn: William F. Friedman, "The Index of Coincidence and Its Applications in Cryptanalysis," Technical Paper, War Department, Office of the Chief Signal Officer. Washington: Government Printing Office, 1935. A 1923 revision of the paper of the same title published in 1922 by the Riverbank Laboratories. p. 11.
- Kasiski's 1863 book and what his method does (repetitions, their spacings factored, the key length, then letter frequencies), in the lesson's definition: David Kahn, "Kasiski, Friedrich W.," in Neue Deutsche Biographie 11 (1977), pp. 317 f.
- Carroll's Alphabet-Cipher card, its example (vigilance, 'meet me on Tuesday evening at seven', the ciphertext the page reproduces) and its promise, in the worked problem; the April 1868 letters about a key-word: Lewis Carroll (C. L. Dodgson), "The Alphabet-Cipher," printed card, undated (c. 1868). Images of both sides and an account of the letters at Lewis Carroll Resources, "Ciphers."