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.
- 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.
- 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.
- 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
- Two-Square cipher: two keyed squares, no doubled-letter rule
- Four-Square cipher: four squares, harder to spot than Playfair
- Bifid cipher: the same square, used as coordinates
- Keyed substitution: the single-letter version of a keyword alphabet