Vigenère cipher is a polyalphabetic substitution cipher. It is a more advanced version of Caesar cipher that was developed to overcome the frequency analysis attacks.

- Read: What does cipher mean.

What this guide include:

I will be discussing the history, how Vigenère cipher works, the maths behind this encryption and how to break(cryptanalysis) this cipher.

- Read: A complete list of ciphers used throughout the history

A short history of this cipher:

It was invented by a French mathematician Blaise de Vigenère in the 16th century. You can think of this cipher as a series of Caesar’s shift to make it harder to break.

### 1) How to solve Vigenère cipher

This cipher uses a string of text ( a keyword) as a key which is used to do multiple alphabetic shifts on the plaintext to encrypt it to ciphertext.

The key is important in determining the number of shifts to be performed across the whole message.

Another thing to note is that the length of the key should be the same as that of the plaintext.

If that is not the case, then the chosen keyword has to be repeated several times until it has the same length as that of the message to be encoded.

After you have the key, all you have to do is shift each letter of the plaintext by the alphabetic number of the matching letter in the keyword.

This is an example of Vigenère cipher:

**How to encrypt using Vigenère cipher**:

**Plaintext**: *CIPHERSANDCODESAREFUN*

**Key**: *KIFANG**A*

To encode a message use this table together with the key(Kifanga) you have decided on:

Now I take the letter that appears at the intersection of the key(letter row) and the plaintext(letter column).

So after doing this for the entire plaintext you get:

**Plaintext**: *CIPHERSANDCODESAREFUN*

**Key**: *KIFANG**AKIFANGAKIFANGA*

**Ciphertext**: *MQUHRXSKVICBJECIWESAN*

**How to decrypt Vigenère cipher**:

To successfully decrypt a message with Vigenère cipher you need both the ciphertext and the key. You just need to replace each letter that’s in the interception of the ciphertext column and key row.

Here is an example for you to practice(use “Vigenère” as your key):

**Ciphertext**: *QQMIAIIIXQVLRVZWVEKWBQV*

**Plaintext**: ?

**How to recognize Vigenere Ciphertext**:

Using a Vigenere encryption, the message has an index of coincidence which decreases between 0.05 and 0.04 which depends on the length of the key. This decreases towards 0.04 the longer the key is.

**How to decipher Vigenere without knowing the key**:

Statistical methods are used to find the length of the key and frequency analysis helps in finding the key.

**Kasiski test**:

This technique involves finding repeating sequences of letters in the ciphertext.

For example XYZ appears three times in the message XYZABCXYZKLMNOPQRSXYZ.

Significance of the repeating letters:

- A similar sequence of letters of the plaintext is encrypted with the same part of the key.
- Different sequences letters are encrypted with different parts of the key but they ends with the same encrypted letters.

An attacker can find multiples of the key length by analyzing the gaps of the same repeating sequences.

This involves analyzing each gaps in terms of number of letters and calculating divisors in order to determine the size of the key.

For example:

Positions of XYZ are 0, 6 and 18, gaps are 6, 12 and 18 letters length. Their divisors are 2, 3 and 6, thus the key length could be either 2, 3 or 6.

**Index of coincidence test**:

Index of coincidence test involves taking one letter out of n in the ciphertext and calculating the IC. The higher the IC, the higher the chance of n being the key size.

- Read: Polybius Square Cipher.

By taking one letter every n where n is the key-length, you end up with a sequence of letters that are always encrypted using the same shift. The index of coincidence is equal to that of the plaintext.

**How to find the key when having both cipher and plaintext**:

During encryption, the key is added to the plaintext to get the ciphertext. So, to get the key, subtract the plaintext from the ciphertext.

You can think of this as decrypting the ciphertext with plaintext as the key. In this case the key appears to be repeated.

Here is an example:

**Plaintext**: Kifanga.

**Key**: ?

By using plaintext (kifanga) as the key to decrypt ciphertext (umdkrek) you get (keykeyk) as your plaintext which actually is the key (KEY) repeated.

**Thus the key is**: KEY.

Try it out using Vigenere cipher decoder/encoder.

**What are the variants of the Vigenere cipher**:

They include: Beaufort Cipher, Vigenere Autoclave Cipher and Vernam Cipher.

**What is the Vernam Cipher**:

Vernam code is a type of Vigenere with the key-length being equal to the plaintext length. This makes it immune to statistical methods because the key could be made of random characters making it hard to break.

Known plaintext attack could be possible when there is a meaning associated with the key.

**What is a Saint-Cyr slide**:

Saint-Cyr slide is a tool that helps in encryption and decryption with Vigenere. It has two alphabet, sliding on one another. To encrypt a letter, simply slide to the above of the key, the letter of the ciphertext correspond to the letter across from the other alphabet.

**Why the name Vigenere**:

Blaise de Vigenère (1523-1596) was a French diplomate, he invented this cipher thus named after him.

**What are the advantages of the Vigenere cipher versus Caesar cipher**:

Did you know that the Caesar cipher is a Vigenere cipher with a 1-letter long key.

- Vigenere code uses longer keys that allows the letters to be encrypted in multiple ways.
- Vigenere code is less prone to frequency analysis and other techniques are needed to successfully break this code.

### 2) Vigenère cipher mathematics

Consider that you want to encrypt a message at letter “p”, then the alphabetic value of “p” will be equal to the plaintext and an addition to the alphabetic value that matches “p” in the key.

Vigenère cipher encryption formula is given by:

Ex = ( Mx + Kp) mod 26

Vigenère cipher decryption formula is given by:

Ex = ( Cx – Kp) mod 26

Where “E” is the code, “M” is the message, “K” is the key and “x” is the nth character of the message(determined by the length of the message) and “p” is the nth character of the key (determined by the length of the key).

### 3) Vigenère cipher variations

Gronsfeld cipher is very similar to Vigenère cipher except that the key used is in numbers instead of letters.

Ways numbers sequence may be determined:

- Pseudo random sequence
- Fibonacci series

That’s the only difference between the two.

There is also the keyed Vigenère cipher variant that is more advanced and more secure.

### 4) How to break (crack) Vigenère cipher

Though this cipher is more secure, it’s still vulnerable to attacks though to a lesser extent.

The most common attacks include:

- Brute force attack, but it’s harder compared to Caesar cipher.
- Frequency analysis attacks

There are a few online tools that you can use to further learn how Vigenère cipher works.

You can encode and decode to text and English or the Language of your choice.

Tools:

### 6) Vigenère cipher code snippets

The following are some examples of source codes that implement this cipher. Use them to learn how this encryption scheme works.

- Vigenère cipher Java program
- Vigenere cipher in Python
- Vigenere cipher program in c++
- Vigenere cipher program in PHP