Playfair cipher is a digraph substitution cipher that was invented by *Charles Wheatstone* in 1854.

It was popularized and promoted by Lord Playfair. Playfair cipher is a manual symmetric encryption type of cipher.

It encrypts pairs of letters commonly called digraphs, unlike other simple substitution ciphers like Caesar cipher that encrypts with a single letter.

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 playfair cipher:

It was used by the British in both “World war 1” and “Second Boer War” for tactical benefits. The Australian forces also used Playfair cipher 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.

Playfair cipher 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

In this guide I will be discussing the following aspects of playfair cipher:

- How to solve playfair cipher (encryption and decryption).
- Cryptanalysis and weakness of playfair cipher.

### 1) How to solve Playfair cipher

To encrypt using playfair cipher, you need to generate a polybius square.

To do this correctly you need a keyword, and you also need to either remove 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 cipher text.

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 have an odd number of characters, in that case you need to append 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.

Here is an example of encryption using playfair cipher:

**Plaintext**: *Learning cryptography is fu**n.*

**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 keyphrase “Playfair cipher”. Then I make sure I don’t repeat any letter that’s already in the square.

Am also going to combine 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 letter “x” at the end of my plaintext.

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

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

Here are three cases that come up during encryption with playfair 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 messsage is given below:

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

- Use this interactive tool: Playfair cipher encoder and decoder.

Decryption of playfair cipher 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.

Playfair cipher exercises for you:

a)

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

**Keyphrase**: Learn ciphers.

**Plaintext (digraphs)**: ?

**Ciphertext**: ?

b)

**Cipher****text**: *Ncryehiotr oehinrpv qbiu.*

**Keyphrase**: Encryption technique.

**Cipher****text (digraphs)**: ?

**Plaintext****ext**: ?

### 2) Cryptanalysis and weakness of playfair cipher.

Playfair cipher is an improvement of the monoalphabetic substitution ciphers that is very easy to use.

Cryptanalysis of playfair cipher can be achieved due to the following weaknesses:

- There are only about 650 possible combinations that can be quickly checked by todays computers in a split second.
- 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”.

Check out this article on how to break playfair cipher.

Now I want to hear from you.

Which part of playfair cipher did you not understand?

Or maybe I missed an important aspect of this cipher.

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