Cipher Table

Playfair cipher

Encipher letters two at a time using a five-by-five square built from a keyword. Because it works on pairs, counting single letters gets an attacker almost nowhere.

Key

How the Playfair cipher works

Build the square. Write the keyword into a 5×5 grid, skipping repeated letters, then fill the rest with the remaining alphabet. I and J share a cell. The live square for your keyword is shown below the tool.

Split the message into pairs. If a pair would be two of the same letter, put an X between them. If one letter is left over at the end, add an X.

Encipher each pair by where its two letters sit in the square:

  1. Same row: replace each with the letter to its right, wrapping round to the start of the row.
  2. Same column: replace each with the letter beneath, wrapping to the top.
  3. Otherwise the two letters mark opposite corners of a rectangle. Replace each with the letter at the other corner on its own row.

To decipher, do the same but move left instead of right and up instead of down. Rule 3 is unchanged.

Why it was a step forward

A simple substitution has 26 things to disguise, and their frequencies give it away. Playfair works on pairs of letters, of which there are about 600, and their frequencies are much flatter. An analyst needs far more text before patterns emerge.

It is also quick. With the square written on a scrap of paper, a soldier could encipher a message in minutes, with no equipment to capture.

History

Charles Wheatstone invented the cipher in 1854. When he and Lyon Playfair showed it to the Foreign Office, it was turned down as too complicated. Wheatstone offered to prove that three out of four boys from the nearest school could learn it in fifteen minutes; the reply, as the story goes, was “That is very possible, but you could never teach it to attachés.”

The British Army adopted it anyway and used it in the Boer War and the First World War. In August 1943, after his patrol boat PT-109 was rammed and sunk, the future president John F. Kennedy’s rescue was arranged through an Australian coastwatcher’s message enciphered in Playfair.

Questions people ask

Why are I and J treated as the same letter?

A 5×5 square has 25 cells and the alphabet has 26 letters, so one pair has to share. By convention J is written as I. Some versions drop Q instead.

Why does an X appear in my decoded message?

Playfair cannot encipher a pair of identical letters, so an X is inserted between doubles ("BALLOON" becomes BA LX LO ON). An X is also added at the end if the message has an odd number of letters. Remove them by eye when reading.

Can the Playfair cipher be broken?

Yes, but not as easily as simpler ciphers. With a few hundred letters, computer search methods such as simulated annealing recover the key square. By hand, analysts used the frequencies of letter pairs and guessed likely words. This site doesn't yet include an automatic Playfair breaker.

Who invented it?

Charles Wheatstone, in 1854. It is named after his friend Lyon Playfair, who championed it to the British government.