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.

Another thing to note is that the length of the key should be the same as that of the plaintext. To put it simply, with this 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.

It was invented by a French mathematician Blaise de Vigenère in the 16th century. Since he’s the one who invented this cipher, it’s therefore named after him. You can think of this cipher as a series of Caesar’s shift to make it harder to break.

Examples of Vigenère cipher variants include:

- Beaufort cipher.
- Vigenère Autoclave Cipher.
- Vernam Cipher.
- Gronsfeld cipher works in the same way except that the key used is in numbers instead of letters.
- There is also the keyed Vigenère cipher variant that is more advanced and more secure.

### Vigenère cipher Example

**Encryption 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 a message

To successfully decrypt a message 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.

**Decryption Example, solve this:**

**Key**: Vigenère

**Ciphertext**: *QQMIAIIIXQVLRVZWVEKWBQV*

**Plaintext**: ?

### Algorithm implementation techniques

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

Encryption formula is given by:

Ex = ( Mx + Kp) mod 26

Decryption function 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).

Here is **Vigenère cipher online JavaScript example**, a real-time **Vigenère cipher decoder** you can play with to learn how this encryption scheme works.

**Vigenère cipher code**. A program implemented in the Python programming language to illustrate this encryption technique.- A C++ program code for this encryption scheme.
- A Java program algorithm.

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

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

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.

Now I want to hear from you.

What do you think of Vigenère cipher?

Or maybe I missed an important aspect of this algorithm.

Either way, let me know by leaving a comment below.