The Vigenère cipher

Kapitoly: The Vigenère cipher, How to break the Vigenère cipher with knowledge of the key length, Estimating the key length of the Vigenère cipher, How to calculate the key length of the Vigenère cipher, Friedman test - coincidence index

The Vigenère cipher is a famous cipher that uses multiple cipher alphabets, making it far more resistant to classical frequency analysis.

The principles of encryption and decryption

The encryption procedure can be explained using the Caesar cipher. The key of the Vigenère cipher is an arbitrary word consisting of the letters of the English alphabet, i.e. a-z. Thus, for example, the key can be the word "bcf". The encryption is then done by writing down the plaintext and immediately below it the key, which is repeated until it is the same length as the plaintext. For the open text "dobryvecer" it would look like this:

Open text:dobryvecer
Key:bcfbcfbcfb

Now we would encrypt all the letters from the plaintext using the Caesar cipher with the appropriate key, i.e., with the key in the same column. The Caesar cipher is a shift cipher, the key indicates how many letters to shift the letter of the plaintext by, measured from the letter "a". For example, the letter "b" indicates a shift of one letter in the alphabet "to the right". The letter "d" indicates a shift of three letters to the right. We would encrypt the word "hello" with Caesar's cipher and the key "b" to "bipk".

While in the Caesar cipher we encrypt the entire text with a single letter, in the Vigenère cipher we typically encrypt with multiple letters. So encrypting the text "dobryvecer" with the key "bcf" would turn out like this:

Open text:dobryvecer
Key:bcfbcfbcfb
Ciphertext:eqgsaafejs

We encrypted the first letter "d" with the key "b", a shift of one letter, hence the result is the letter "e". We encrypted the first letter "o" with the key "c", a shift of two letters, resulting in the letter "q". Etc.

We decrypt in exactly the same way, only instead of shifting the letters "right", we shift them "left".

The online tool for encrypting and decrypting the Vigenère cipher

Text:
Key:

Vigenère square

The entire encryption and decryption process can also be explained using the Vigenère square, which is a tool that we can use during encryption. A Vigenère square is a table that has 26 rows and 26 columns. In each row, an alphabet is inscribed, and in each row it is always shifted by one letter:

If we have such a Vigenère square, the encryption would proceed as follows: we would take a letter from the open text and find the row with that letter. Then we would take a letter from the key and find the column. The letter from the ciphertext would then be the letter from the corresponding row and column.

In the previous example, we encrypted "dobryden" with the key "bcf". So we find a row that starts with "d", a column that starts with "b". At the intersection of this row and column is the letter "e", the resulting ciphertext letter.

When decrypting, we would do the reverse. If we wanted to decrypt the letter "e" using the key "b", we would find the column "b", in it we would find the row that contains the letter "e", and the letter that is at the beginning of that row would be the letter from the plaintext.

The main strength of the Vigenère cipher

Why was the Vigenère cipher so strong in its time? Because it made classical frequency analysis very difficult. For example, in the Caesar cipher, two identical letters in the plaintext are encrypted to the same letters in the ciphertext. But this is not true in the Vigenère cipher, at least not always.

If we encrypted the text "Okay okay okay" with the key "tent", we would get the ciphertext "vhbew woojx dbtke". We can see that even though the plaintext contains the same three words, each word looks completely different in the resulting ciphertext. The middle word, "woojx", even contains two letters "o", but they are formed from two different letters of the plaintext: "ob".

Choice of key

The security of the Vigenère cipher is very much affected by the choice of key. Whereas in Caesar's cipher it did not matter which letter was chosen as long as it was different from "a", in Vigenère's cipher different keys lead to different levels of cipher security.

  • A key that consists of only one letter reduces the Vigenère cipher back to the Caesar cipher.
  • A key that consists of multiple identical letters, such as "mmm", will again lead to the Caesar cipher.
  • The text encrypted with the short key will be very easy to crack.
  • A sufficiently long ciphertext that has been encrypted with a not-quite-short key (about fifty characters) will also be very easy to crack. On a computer in seconds.
  • A ciphertext encrypted with a key that is completely random and as long as the ciphertext itself will be impossible to crack.