CipherTools

Playfair Cipher

The Playfair cipher uses a 5 x 5 Polybius square:

G O R D N
B A K S C
E F H I L
M P Q T U
V W X Y Z

This particular Polybius square has been built around the key 'GORDON BANKS'. The key is entered into the square, although the second instance of each letter is skipped over (the second 'O' in GORDON and the 'N' in BANKS). Once the key has been entered, the remaining letters of the alphabet complete the square. But, because there are only 25 spaces, the letter 'J' is omitted (at least, this is what we will assume here - it is possible to omit other letters, e.g. 'Q').

It is not necessary to arrange the 25 letters in the Polybius square on the basis of a keyword. You could, for example, arrange the 25 letters completely randomly.

Enciphering a message

To encipher the message THEBASICCELL, we take each pair of letters in turn from the plain text: TH, EB, AS, IC etc., and we locate the two letters in the pair on our Polybius square.

Two plaintext letters form a square

So, starting with the first pair of TH:

G O R D N
B A K S C
E F H I L
M P Q T U
V W X Y Z

We can see that the two letters TH form the diagonal of a square, and this is what happens most often when you locate two letters in the square. In this case, the mini-square is just 2 letters wide, but any width of mini-square up to 5 letters is possible. Once you have identified the square, you can find the two ciphertext letters by reading the letters in the other two corners of the square. The order in which they are read is important:

  • The first ciphertext letter is the corner letter that shares the same row as the first plaintext letter. In this example, the first plaintext letter is T, so the corner letter that shares the same row is Q.
  • The second ciphertext letter is the corner letter that shares the same row as the second plaintext letter. In this example, the second plaintext letter is H, so the corner letter that shares the same row is I.

Our first two ciphertext letters, therefore, are QI, corresponding to the first two plaintext letters of TH.

Two plaintext letters are in the same column

The next pair of letters in THEBASICCELL are EB. These fall in the same column:

G O R D N
B A K S C
E F H I L
M P Q T U
V W X Y Z

When the two plaintext letters fall in the same column, the ciphertext letters can be found by looking at the letter below each plaintext letter. Once again, the order is important:

  • The first ciphertext letter is the letter immediately under the plaintext letter that occurs first in the message. In this example, the first plaintext letter is E, so the letter underneath is M.
  • The second ciphertext letter is the letter immediately under the plaintext letter that occurs second in the message. In this example, the second plaintext letter is B, so the letter underneath is E.

The next two ciphertext letters, therefore, are ME, corresponding to the two plaintext letters of EB.

What would have happened if one of the plaintext letters was placed at the bottom of a column? In such cases, you wrap back around to the top of the column and the ciphertext letter becomes the letter at the top of that column. A plaintext letter of V, for example, would become a G when using this Polybius square.

Two plaintext letters are in the same row

The next pair of letters in THEBASICCELL are AS. These fall in the same row:

G O R D N
B A K S C
E F H I L
M P Q T U
V W X Y Z

When the two plaintext letters fall in the same row, the ciphertext letters can be found by looking at the letter to the right of each plaintext letter. As before, the order is important:

  • The first ciphertext letter is the letter immediately to the right of the plaintext letter that occurs first in the message. In this example, the first plaintext letter is A, so the letter to the right is K.
  • The second ciphertext letter is the letter immediately to the right of the plaintext letter that occurs second in the message. In this example, the second plaintext letter is S, so the letter to the right is C.

The next two ciphertext letters, therefore, are KC, corresponding to the two plaintext letters of AS.

What would have happened if one of the plaintext letters was placed on the far-right of a row? In such cases, you wrap back around to the left of the row and the ciphertext letter becomes the letter on the far-left of that row. A plaintext letter of C, for example, would become a B when using this Polybius square.

So far, we have enciphered THEBAS as QIMEKC.

The next two pairs are straightforward, as each pair forms the corners of a square, as with the first pair considered above. IC becomes LS, and CE becomes BL.

We have now enciphered THEBASICCE as QIMEKCLSBL. It appears as though we have just one pair left: LL. But now we have a problem ...

The two plaintext letters in a pair are the same

We are trying to encipher this plaintext pair: LL:

G O R D N
B A K S C
E F H I L
M P Q T U
V W X Y Z

Whenever a double letter falls within a pair, it is necessary to insert an extra letter between the two identical letters. Typically, that extra letter is an X. So the LL in our case becomes LXL. We still only work with pairs, so our new pair becomes LX. We shall deal with the last L shortly.

LX is another straightforward pair:

G O R D N
B A K S C
E F H I L
M P Q T U
V W X Y Z

Using the 'corners of a mini-square' rule, as described above, LX becomes HZ.

But we still have one L left over ...

What to do if there is a single letter left at the end of a message

The original message of THEBASICCELL started off with an even number of letters. We have now enciphered six pairs, so we should have finished, but, because we had to insert an extra letter when we got to the double LL, we are still left with a single L at the end. When this happens, the rule is to add on another letter to turn it into a pair. Again, this letter is usually an X, but other letters are possible. We will use an X, so our final pair is LX. This turns out to be exactly the same as our previous pair, and we have just seen that this turned into HZ.

So, the final result of enciphering THEBASICCELL with this Polybius square is QIMEKCLSBLHZHZ.

What to do if plaintext letter is the one that does not appear in the square

When we created the 5 x 5 Polybius square earlier, we left out the letter J. So what do we do if we come across a J in the plaintext? The answer is that it is replaced by another plaintext letter, and a J is typically replaced by an I. Once the swap has been made, the plaintext pair is then enciphered using one of the normal ways described above.

Identifying a Playfair cipher

A message enciphered with a Playfair cipher will display the following characteristics:

  • The ciphertext will consist of an even number of letters. This is because all the plaintext letters are enciphered in pairs, with an extra plaintext letter being added on at the end if necessary.
  • The ciphertext will never have all 26 letters present. This is because the enciphering square is typically 5 x 5, so it only has room for 25 letters. There is a good chance that the missing letter will be a J.
  • Once the ciphertext is split into pairs, no pair will ever contain the same two letters (e.g. LL). If you look through all the ways above, which show how a plaintext pair can be enciphered with the Playfair cipher, you will see that it is impossible for any of the ways to generate a pair of identical letters. I have worded this carefully: it is possible for there to be two identical letters in a row in the ciphertext, but this will only happen if the two adjacent letters actually belong to two different pairs. Once the ciphertext is split into pairs, no pair will ever contain the same two letters.
  • The ciphertext will display a low Index of Coincidence score, e.g. somewhere between 0.04 and 0.05, whereas normal English is typically around 0.066. One of the reasons for this is that the enciphering methods described above mean that the same plaintext letter can be converted into a range of different ciphertext letters. For example, in the square above, the plaintext GA becomes OB, whereas the plaintext GH becomes RE. In the first case, G becomes O, but in the second case it becomes R.

Cipher Challenge competition    Leave feedback