Free Tool

Playfair Cipher Tool

Encrypt and decrypt with a 5×5 keyword square, pair by pair

Ciphertext

How the Playfair cipher works

The Playfair cipher encrypts pairs of letters instead of single letters, which hides the letter frequencies that make simple substitution easy to break.

  1. Build the key square. Write the keyword's letters into a 5×5 grid, skipping any already used, then fill the rest with the unused letters of the alphabet. I and J share a cell.
  2. Split the message into pairs. Drop spaces and punctuation. If a pair would be two identical letters, put an X between them. If one letter is left at the end, add an X.
  3. Encrypt each pair with whichever of these three rules fits:
    • Same row: take the letter to the right of each (the row wraps round).
    • Same column: take the letter below each (the column wraps round).
    • Anywhere else: the two letters mark opposite corners of a rectangle. Take the other two corners, keeping each letter's row.

Decryption runs the same rules backwards: left instead of right, up instead of down. The rectangle rule is the same both ways.

Example

With the keyword PLAYFAIR EXAMPLE, the square starts P L A Y F / I R E X M. The message HIDE THE GOLD IN THE TREE STUMP splits into HI DE TH EG OL DI NT HE TR EX ES TU MP (an X splits the double E in TREE) and encrypts to BMODZBXDNABEKUDMUIXMMOUVIF.

How to break it

  • Pair frequencies. Common English pairs such as TH, HE, IN and ER become common cipher pairs. Count the cipher pairs first.
  • Reversals. If AB encrypts to XY, then BA always encrypts to YX. Spotting a reversed pair in the ciphertext often reveals a word like RE/ER.
  • No doubles. A ciphertext pair is never two identical letters, and no letter ever encrypts to itself. A ciphertext with doubled pairs isn't Playfair.
  • A known word. Guessing one word in the message (a name, a place) gives several pairs at once, and each pair pins down where letters sit in the square.

History

Charles Wheatstone invented the cipher in 1854, but his friend Lord Playfair promoted it so well that it carries his name. The British used it as a field cipher in the Boer War and the First World War, and Allied forces still used it in the Second World War: a Playfair message from coastwatchers helped rescue John F. Kennedy's PT-109 crew in 1943.

Related tools

Questions

Why does my decrypted Playfair message have extra X letters?

Before encrypting, an X goes between two identical letters that would land in the same pair (BALLOON becomes BA LX LO ON), and one more is added if the message has an odd number of letters. Decrypting gives them back. Read past them; they are not part of the message.

What happens to the letter J?

The square has 25 cells, so I and J share one. J is written as I before encrypting, and decrypting always gives I. Context tells you which was meant.

Is the Playfair cipher secure?

No. It was good enough for battlefield messages that only had to stay secret for a few hours, but with a page or so of ciphertext a computer search finds the key square in seconds.