What is Playfair Cipher (with Example)

Playfair cipher is a digraph substitution cipher.

To put it simply, Playfair cipher 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.

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

A brief history of Playfair cipher:

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

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.

Playfair cipher

In this guide I will be discussing the following:

  • How to solve the Playfair cipher.
  • How to crack a Playfair cipher.

How to solve Playfair cipher

How to encrypt using Playfair cipher

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.

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:

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 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 message is given below:

Ciphertext: Frlcubqb hcflnqdcylkh hn pzsU

How to decrypt Playfair cipher

Decryption of the 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.

Try out the following examples:


Plaintext: Playfair is a powerful cipher.

Keyphrase: Learn the ciphers.

Plaintext (digraphs): ?

Ciphertext: ?


Ciphertext: Ncryehiotr oehinrpv qbiu.

Keyphrase: Encryption technique.

Ciphertext (digraphs): ?

Plaintextext: ?

Here is a tool to decrypt/encrypt Playfair automatically.

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

Are you interested in learning how to break codes?

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

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.


Please enter your comment!
Please enter your name here