Chapter 21 – Hacking the Vigenère Cipher 323
The factors that have the highest count are the most likely lengths of the Vigenère key. In
our example above, these are 2, 4, and 8. The Vigenère key is probably 2, 4, or 8 letters long.
Get Every Nth Letters from a String
For this example, we will guess that the key length is 4. Next we will want to split up the
ciphertext into every 4th letter. This means we want the following underlined letters as a separate
string:
Every 4 th letter starting with the first letter:
PPQCAXQVEKGYBNKMAZUYBNGBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITLAZUVAVVRAZCVKBQPIWPOU
Every 4 th letter starting with the second letter:
PPQCAXQVEKGYBNKMAZUYBNGBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITLAZUVAVVRAZCVKBQPIWPOU
Every 4 th letter starting with the third letter:
PPQCAXQVEKGYBNKMAZUYBNGBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITLAZUVAVVRAZCVKBQPIWPOU
Every 4 th letter starting with the fourth lettter:
PPQCAXQVEKGYBNKMAZUYBNGBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITLAZUVAVVRAZCVKBQPIWPOU
When combined, they become these four strings:
Every 4th letter starting with the first letter: PAEBABANZIAHAKDXAAAKIU^
Every 4th letter starting with the second letter: PXKNZNLIMMGTUSWIZVZBW
Every 4th letter starting with the third letter: QQGKUGJTJVVVCGUTUVCQP^
Every 4th letter starting with the fourth letter: CVYMYBOSYRORTDOLVRVPO^
If our guess from Kasiski Examination was correct and the decryption key was in fact 4
characters long, then the first subkey of the key would have been used to encrypt the characters in
the first string above, the second subkey of the key would have been used to encrypt the
characters in the second string above, and so on.
Frequency Analysis
Remember, the Vigenère cipher is the same as the Caesar cipher, except it uses multiple subkeys.
Kasiski Examination tells us how many subkeys were used for the ciphertext, now we just have to
hack each subkey one at a time. Let’s try to hack the first of these four ciphertext strings:
PAEBABANZIAHAKDXAAAKIU
We will decrypt this string 26 times, once for each of the 26 possible subkeys, and then see what
English frequency match score the decrypted text has. In the table below, the first column is the
subkey used to decrypt the PAEBABANZIAHAKDXAAAKIU string. The second column is the
returned decrypted text value from vigenereCipher.decryptMessage(subkey,