A Playfair cipher is a digraph substitution cipher that uses a table where one letter of the alphabet is omitted, and the letters are arranged in a 5 by 5 grid. The letter J is often replaced with the letter I in the plaintext.

For example, in Playfair cipher, the plaintext “**ATTACK**” would be broken into two-letter chunks thus becoming “**AT TA CK**”.

Finally, the positions of the letter pairs are looked up in the grid to get the resulting ciphertext.

You can still break this cipher using frequency analysis technique but the number of possible combinations is very high compared to other simple substitution ciphers.

- Check out: Complete list of ciphers.

There exactly “600 possible pairs of letters” in this encryption scheme.

A brief history of this encryption scheme:

It was invented by *Charles Wheatstone* in 1854. It was later popularized and promoted by Lord Playfair.

It was used by the British in both “World war 1” and “Second Boer War” for tactical benefits. The Australian forces also used it during the second world war.

The advantages of **Playfair cipher**:

- This cipher is surprisingly fast in execution.
- It does not need special equipment in order to work properly.

It was commonly used for protection of secrets that were important but not critical in the times of war.

The messages encrypted with it changed very fast making it hard for the enemies to find any valuable information even after successfully breaking the encoded message.

### Playfair Cipher Example

First, you need to generate a Polybius square.

To do this correctly you need a keyword, and you also need to either remove the letter “q” from the table or merge letters “j” and “i”.

The table is a 5 by 5 grid of letters that you will later use to encode your plaintext into ciphertext.

Note that each of the 25 letters needs to be unique and often the letter “q” is omitted to form a perfect square since the normal alphabet is made up of 26 characters.

Next, you need to divide your plaintext into pairs of letters. If your plaintext has an odd number of characters, in that case, you need to append an uncommon letter like “X” to make the digraph complete.

- Read: Polybius Square Cipher.

Here are fours encryption steps performed on each digraph:

- If there is only a single letter left by itself at the end of your plaintext, then you are required to insert the letter “X” between the same letters, or at the end.
- If the two letters appear on the same row in the square, then you are required to replace each letter by the letter immediately to the right of it in the square.
- If the two letters appear in the same column in the square, then you need to replace each letter by the letter immediately below it in the square.
- Else, form the rectangle for which the two plaintext letters are two opposite corners. Then replace each plaintext letter with the letter that forms the other corner of the rectangle that lies on the same
**row**as that of plaintext letter.

**Encryption example:**

**Plaintext**: *Learning cryptography is fun.*

**Keyphrase**: *Playfair cipher.*

So in order to encrypt my plaintext, I first generate a square (Polybius) that am going to use.

I need to set out a 5 by 5 grid and fill it with alphabet starting with the letters of my key phrase “Playfair cipher”. Then I make sure I don’t repeat any letter that’s already in the square.

Am also going to combine the letter “i” and “j”.

Then I divide my plaintext into digraphs and in case of a double letter digraphs I inserting an “x” between them (application of rule 1).

**Plaintext (digraphs)**: *Le ar ni ng cr yp to gr ap hy is fu n.*

In my case, I don’t have double letter digraphs but instead, I have an odd number of letters of my plaintext.

So I add the letter “x” at the end of my plaintext.

**The resulting plaintext (digraphs)**: *Le ar ni ng cr yp to gr ap hy is fu nx.*

Then to encrypt each digraph I need to apply rule 2, 3 or 4.

Here are three cases that come up during encryption with this cipher:

The pair of letters colored in green represent the plaintext digraphs and the ones colored in red are ciphertext digraphs after the encryption has been performed.

*Case 1:*

*Case 2:*

*Case 3:*

**The resulting ciphertext (digraphs)** : *Fr lc ub qb hc fl nq dc yl kh hn pz sU*

Thus, my final encrypted message is given below:

**Ciphertext**: **Frlcubqb hcflnqdcylkh hn pzsU**

#### How to decrypt a message

Decryption is equally easy and takes the same process except for the rule 2 where letters are taken to the left and rule 3 where letters are taken above.

- Read: What is a cipher.

Try out the following examples:

a)

**Plaintext**: Playfair is a powerful cipher.

**Keyphrase**: Learn the ciphers.

**Plaintext (digraphs)**: ?

**Ciphertext**: ?

b)

**Ciphertext**: *Ncryehiotr oehinrpv qbiu.*

**Keyphrase**: Encryption technique.

**Ciphertext (digraphs)**: ?

**Plaintextext**: ?

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

### Cryptanalysis of Playfair Cipher

This algorithm is an improvement of the monoalphabetic substitution ciphers that is very easy to use.

This encryption scheme can be easily broken due to the following weaknesses:

- There are only about 650 possible combinations that can be quickly checked by today’s computers in a split second.
- The same pair of letters when reversed will always produce the same pair of letters reversed. For example: if plaintext “FG” is encrypted to “SA”, then the plaintext “GH” will encrypt to “AS”.

### How to recognize Playfair ciphertext

The encoded message has an even number of letters. The message may have 25 distinct letters at most (the number of letters in the grid).

It is impossible to find a bigram composed of 2 identical letters. It is impossible that a letter is encrypted by itself

### How to decipher Playfair without grid

Playfair can be cracked using a known plaintext attack in order to discover a part of the grid.

### Multiple grids can fit a Playfair cipher

Several squares can be used for the same decryption of Playfair.

Once a square grid of 25 is found, other squares obtained from the previous by rotating rows and columns gives the same result.

What are the variants of the Playfair cipher

Multiple variants can be found when encrypting bigrams.

When letters are in a column or in lines, it is possible to encode with the one on the right or on the left, or above or below.

Also, when the letters are diagonally positioned, it is possible to write letters1-letter2 or letter2-letter1.