The Playfair cipher was the first practical digraph substitution cipher, encrypting pairs of letters at a time instead of single letters. Invented in 1854 and named after Lord Playfair, it was used for tactical military messages because it could be performed by hand yet resisted casual frequency analysis. This tool builds the keyword square and applies the real rules in your browser.
How it works
First build a 5×5 square: write the keyword (dropping repeats) into the grid, then fill the remaining cells with the rest of the alphabet. Because the grid has 25 cells, I and J share one cell.
Split the plaintext into pairs. If a pair would contain two identical letters, insert an X between them; if the message has an odd length, pad the final letter with X. Then apply three rules to each pair:
- Same row: replace each letter with the one immediately to its right, wrapping around.
- Same column: replace each letter with the one immediately below it, wrapping around.
- Rectangle: replace each letter with the one in its own row at the other letter’s column.
Decryption uses the same rules but shifts left and up instead of right and down.
Building the square step by step
Take the keyword MONARCHY. Write it out, skipping any repeated letters: M O N A R C H Y. Then continue with the unused letters of the alphabet in order, skipping I (merged with J): B D E F G I/J K L P Q S T U V W X Z. The resulting square is:
M O N A R
C H Y B D
E F G I K
L P Q S T
U V W X Z
Every keyword produces a unique square, and the entire cipher’s security rests on keeping the keyword secret.
Worked example: encrypting BALLOON
The word BALLOON contains repeated letters that need handling before encryption. Steps:
- Pair the letters:
BA LL OO N. - The pair
LLhas two identical letters — insert X:BA LX LO ON. - No trailing single letter, so no final-X pad needed.
- Now encrypt each digraph against the MONARCHY square above.
For the BA pair: B is at row 1 col 3; A is at row 0 col 3 — same column, so each shifts one row down: B → I, A → B. Output: IB. Continuing through each pair produces the ciphertext.
Why Playfair resists simple frequency analysis
Standard Caesar and simple substitution ciphers preserve letter frequency, so common letters (E, T, A in English) show up frequently in the ciphertext and reveal themselves. Playfair encrypts pairs, so the 26 single-letter frequencies are replaced by 676 possible digraph frequencies, which is far harder to exploit — especially in short messages. However, patterns in common digraphs (TH, HE, IN) can still leak information to a determined analyst with enough ciphertext, and the cipher was broken by British intelligence in the early twentieth century.
Comparison with related ciphers
| Cipher | Unit encrypted | Key type | Resistance to frequency analysis |
|---|---|---|---|
| Caesar | Single letter | Shift | Very low |
| Vigenère | Single letter | Keyword (repeating) | Low to moderate |
| Playfair | Letter pair | 5×5 keyword square | Moderate |
| Four-square | Letter pair | Two 5×5 squares | Moderate |
| Enigma | Single letter | Rotor settings | High (for its era) |
Notes on decryption and padding
Decrypted output will include any padding X letters that were inserted before encryption. These are usually obvious from context — BALXLOON decrypts back to BALLOON. Since I and J share a cell, context tells you which was meant: BALLON containing an I/J cell should be read as the letter that makes a real word.