Vigenère cipher is a polyalphabetic substitution cipher that uses a keyword to do multiple alphabetic shifts on the plaintext. The encryption of the plaintext is done using the Vigenère square or Vigenère table.

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

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

- Read: What does cipher mean.

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

To put it simply, for Vigenère cipher 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.

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

A brief history of Vigenère 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.

Are you interested in **finding out more about ciphers and codes**?

The Codebreakers – The Story of Secret Writing book by David Kahn is what I would start with.

## Vigenère Cipher

In this guide I will be discussing the following:

- How to solve the Vigenère cipher.
- How to crack a Vigenère cipher.

### How to solve Vigenère cipher

#### How to encrypt using Vigenère cipher

**Here is an example:**

**Plaintext**: *CIPHERSANDCODESAREFUN*

**Key**: *KIFANGA*

To encode a message using 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**: *KIFANGAKIFANGAKIFANGA*

**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:

**Key**: Vigenère

**Ciphertext**: *QQMIAIIIXQVLRVZWVEKWBQV*

**Plaintext**: ?

### 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).

### 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.

### How to crack a 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.

Here is a tool to decrypt/encrypt Vigenère automatically.

#### How to recognize Vigenère Ciphertext

Using a Vigenère 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 Vigenère 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.

The 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 end 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 gap in terms of the 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 long. Their divisors are 2, 3 and 6, thus the key length could be either 2, 3 or 6.

Are you interested in learning **how to break codes**?

The Elementary Cryptanalysis – A Mathematical Approach book by Abraham Sinkov is what I would recommend.

**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.

#### What are the variants of the Vigenère cipher

They include Beaufort Cipher, Vigenère Autoclave Cipher, and Vernam Cipher.

#### What is the Vernam Cipher

Vernam code is a type of Vigenère 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 Vigenère. It has two alphabets, sliding on one another. To encrypt a letter, simply slide to the above of the key, the letter of the ciphertext corresponding to the letter across from the other alphabet.

#### Why the name Vigenère

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

#### What are the advantages of the Vigenère cipher versus Caesar cipher

Did you know that the Caesar cipher is a Vigenère cipher with a 1-letter long key?

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

### Vigenère cipher code snippets

Here is the Vigenère source code for C, C++, C#, VB.Net, and PHP.