Skip to 0 minutes and 2 seconds A Vigenere cipher involves using multiple Caesar ciphers to encrypt a message, making it much harder to crack. To encrypt your message, you need a key of random letters. The longer the key, the harder it is to break the encryption. You also need a Vigenere square, which you can make using a 26 by 26 cell grid or spreadsheet. Write the alphabet in the first row and column, like this. Then fill each column, starting with the letter in the top cell. When you reach Z, begin the alphabet again. You will end up with something that looks like this. To encrypt your message, you substitute each letter with another, using your key to find the intersection of the correct row and column.

Skip to 0 minutes and 42 seconds For example, if the message is hello, you encrypt the first letter H using row H. Then you use the first letter of your key to choose the correct column. Your key here is RPI, so you need to find the intersection of row H with column R, which gives you the letter Y. You then repeat this for the second letters of the message and of the key, the third letters, and so on. If your message is longer than your key, you loop through the letters of the key in order until your entire message is encrypted. So here, hello becomes Y-T-T-C-D. To decrypt a Vigenere cipher text, you reverse the process.

Skip to 1 minute and 17 seconds First, find the row that corresponds to the first letter in the key. And in that row, find the first letter in the cipher text. The letter at the top of this column is your first plain text letter. Then repeat the process for each letter in the cipher text. Previously, you broke the Caesar cipher by looking for patterns in a text that were preserved by the encryption scheme. The Vigenere cipher isn’t so easy to break, because the substitution is different for each letter. That means it’s harder to spot patterns or frequently used letters. However, it’s not unbreakable. In the Second World War, British spies used the lines of famous poems as their keys.

Skip to 1 minute and 52 seconds When German code breakers figured this out, it became easy to guess the keys and decrypt the messages. Patterns in a cipher text can still provide clues for figuring out the key. A repeated sequence of letters is more likely to be the same part of a word that was encrypted using the same part of the key rather than two different sets of letters encrypted to produce the same sequence. Dragging is another technique used to crack the cipher. By guessing a word from the message, you can check whether it’s been encrypted at every possible position until you find a likely key. For example, imagine you intercept a message from Alanis Morissette. And you suspect that she’s been talking about the weather.

Skip to 2 minutes and 30 seconds You could check whether the word rain has been encrypted until you can guess part of the key. Once you have a clue to the key, you can try to decrypt the rest of the message. If you haven’t found the whole key, you might need to try multiple approaches until you can spot patterns in the message. This method of decryption requires more deduction and guesswork than the Caesar cipher. Now, you have a go at decrypting this message about the future of course.

# Vigenère cipher

In this step we will look at the Vigenère cipher.

As you learned a few steps ago, the Vigenère cipher is a **polyalphabetic cipher** from the 16th century. It uses multiple Caesar ciphers to encrypt a message, adding to the complexity of the cipher and making it hard to crack.

### The encryption process

To encrypt a message, you need to create a key and a Vigenère square.

The key is a string of letters: the longer and more random it is, the harder the encryption will be to break. A Vigenère square is a grid formed by repeatedly writing the alphabet, starting at different places.

To encrypt a message, you will replace each letter in the message with another letter, chosen by finding the intersection of the correct row and column. To choose the row, find the letter of your message in the first column. If your message was “hello”, the first letter would be encrypted using the row beginning with the letter “h”.

To choose the correct column, you need your key. For the first letter in your message, choose the column that starts with the first letter in the key; for the second letter in your message, choose the column that starts with the second letter of your key, and so on. For instance, if your key was “key”, the first letter in the message would be encrypted using the column beginning with the letter “k”, the second letter would be encrypted using the column beginning with the letter “e”, and the third using the column beginning with the letter “y”. If you message is longer than your key, simply reuse the letters in your key in order.

Using this process, the letter “h” is encrypted as “r”, and the letter “e” is encrypted as “i”. The first “l” becomes “j”, but the second “l” becomes “v”. Finally, the letter “o” becomes “s”. This encrypts the word “hello” as “rijvs”.

Test your understanding of the method by encrypting the following message using your Vigenère square:

```
I am encrypting a message
```

To decrypt a message, you reverse the process by first finding the row that corresponds to the nth letter in the key, then looking along that row until you find the nth letter in the ciphertext. The letter at the top of this column is the plaintext letter.

If we take our ciphertext “rijvs”, to decrypt it we start at row “k” and find the position of the letter “r” in this row. At the top of this column is the letter “h” — the first letter of our plaintext.

### Breaking the Vigenère cipher

In this last step you saw how a variety of techniques can be used to decrypt a Caesar cipher, even without knowing the key. This is because the patterns in the text are preserved by the encryption scheme. This is not the case for the Vigenère cipher, which is more complex. The number of places a letter is shifted in the alphabet can change for each letter in the message, which means the most frequently used letter in the ciphertext does not correspond to the most frequently used letter in the plaintext. Additionally, if you find a letter used twice consecutively in the ciphertext, that does not mean that there is a double letter in that position in the plaintext.

The Vigenère cipher took a lot longer to break than the Caesar cipher because of these features.

However, it is not unbreakable. In the Second World War, spies used the lines of famous poems as their keys. When German codebreakers figured out this pattern, it became easier to guess a ciphertext’s encryption key and decrypt the message. If you can guess the key that was used to encrypt a message, you can decrypt the message.

Patterns in ciphertext do still provide some clues. A sequence of letters repeated in multiple places is still more likely to be the same word (or part of a word), encrypted using the same part of the key. It is less likely that these repeats are two different sets of letters being encrypted as the same pattern.

Another technique that can be used to crack the cipher is called **dragging**. If you think you know a word or phrase that will be in the message, you can test if the word has been encrypted anywhere in the message until this process produces a key that appears not to be random.

When you have a clue to the key, you can try to decrypt the rest of the message. If you haven’t found the whole key, this process also involves trying multiple approaches until you can spot patterns in the message.

This method of decryption requires more deduction and guesswork than the Caesar cipher.

### Tasks

- Create key generation, encryption, and decryption algorithms for the Vigenère Cipher
- Can you use your algorithms to decrypt the following message about the FutureLearn course using the key “futurelearn”?

```
Ybbm cmqi tyny c aumi
Tw acy ybtn z llze
Rai uef kllx i ynay
Bm psfvs
```

Share your algorithms in the comments section.