Playfair Cipher
Classic 5×5 digraph substitution cipher.
Overview
The Playfair cipher tool encrypts and decrypts text using a 5×5 grid keyed on a passphrase, operating on pairs of letters (digraphs) rather than single characters. Type a key and a message, and the tool walks through every digraph, applying Playfair's row/column/rectangle rules to produce the output.
It is a classic teaching cipher and a frequent appearance in cryptogram puzzles and CTFs. If you are revisiting Charles Wheatstone's 1854 invention (popularised by Lord Playfair) or trying to recover a Boy Scouts of America cipher message, this Playfair cipher solver gives you a quick crosscheck.
How it works
The cipher fills a 5×5 square with a deduplicated keyword followed by the remaining letters of the alphabet, treating I and J as one (or sometimes dropping Q). The plaintext is preprocessed: spaces removed, doubled letters split by an X filler (LL → LX-LO), and an X appended if the length is odd.
Each digraph is then encrypted by one of three rules:
- Same row — replace each letter with the one to its right (wrapping).
- Same column — replace each letter with the one below it (wrapping).
- Rectangle — replace each letter with the one in its row on the column of the other letter.
Decryption uses the same rules in reverse: shift left in rows, up in columns, and the rectangle rule is its own inverse.
Examples
Key: PLAYFAIR EXAMPLE
Grid: P L A Y F / I R E X M / B C D G H / K N O Q S / T U V W Z
Plaintext: HIDE THE GOLD
Pairs: HI-DE-TH-EG-OL-DX
Output: BM-OD-ZB-XD-NA-BE → BMODZBXDNABE
Key: KEY
Plaintext: HELLO
Padded: HE-LX-LO
Output: RI-PT-QM (example values; depends on grid)
Ciphertext: BMODZBXDNABE
Key: PLAYFAIR EXAMPLE
Output: HIDETHEGOLDX (trailing X is filler)
FAQ
Why are I and J merged?
The 5×5 grid only fits 25 letters, so one pair must collapse. The standard convention is I/J, which is what most textbooks and CTF challenges expect.
What does the X mean in the output?
It is filler. Playfair never encrypts identical letters in a digraph, so doubles like LL are split with an X between them. A trailing X shows up when the plaintext length is odd.
How was Playfair broken?
Frequency analysis on digraphs. English has a strongly skewed digraph distribution (TH, HE, IN, ER are common), so once enough ciphertext is captured the underlying grid leaks. Computer-aided hill-climbing solvers crack it in seconds.
Why is it called Playfair if Wheatstone invented it?
Wheatstone invented the cipher; Lord Playfair championed it within the British government, and the name stuck. It saw real use in the Boer and First World Wars for tactical messages.