Playfair Cipher
Digraph substitution cipher with a 5×5 keyword square — encrypt and decrypt paired letters.
How to Use the Playfair Cipher Tool
- Enter a keyword — type any keyword (e.g., MONARCHY) and click Apply. The 5×5 key square updates automatically.
- Choose Encrypt or Decrypt — select the direction with the option chips.
- Enter your text — type or paste plaintext. Letters only; spaces and punctuation are ignored.
- View the output — the encrypted (or decrypted) text appears on the right.
- Key Square tab — see the current 5×5 grid used for encryption.
About the Playfair Cipher
The Playfair cipher was invented by Sir Charles Wheatstone in 1854 but popularized by Lord Lyon Playfair, who advocated its use to the British Foreign Office, giving the cipher its name. It was the first practical digraph substitution cipher in widespread use. Unlike simple monoalphabetic ciphers, Playfair encrypts pairs of letters, making simple frequency analysis much harder to apply.
Building the Key Square
The 5×5 key square is built from a keyword: write the unique letters of the keyword left-to-right, top-to-bottom in the grid, then fill in the remaining unused letters of the alphabet in alphabetical order. I and J share one cell (typically both mapped to I). For the keyword MONARCHY, the grid starts: M, O, N, A, R, C, H, Y then continues B, D, E, F, G, I/J, K, L, P, Q, S, T, U, V, W, X, Z.
The Three Encryption Rules
The plaintext is divided into digraphs (pairs). If a pair has the same letter, an X is inserted between them. If the message has an odd length, X is appended. Then for each digraph:
- Same row: replace each letter with the letter immediately to its right in the row (wrapping around).
- Same column: replace each letter with the letter immediately below it in the column (wrapping around).
- Rectangle (different row and column): each letter is replaced by the letter in the same row but in the column of the other letter of the pair.
Decryption uses the same rules in reverse: shift left instead of right, shift up instead of down, and the rectangle rule is the same (it is symmetric).
Historical Use
The Playfair cipher was used extensively by the British military during World War I and was also used by the Australians and British in World War II. It was considered secure enough for tactical communications but not for high-level strategic messages, which used more complex cipher systems. The cipher gained cultural fame when John F. Kennedy, stranded after the sinking of PT-109, used a Playfair cipher to encode a rescue message scratched onto a coconut shell.
Cryptanalysis
With sufficient ciphertext (around 200 characters), Playfair can be broken using frequency analysis of digraphs rather than individual letters. The cipher produces 676 possible digraphs (26×26), but since I and J are merged and certain rules apply, patterns emerge. Importantly, Playfair never maps a digraph to the same reversed digraph: if AB encrypts to XY, then XY encrypts to AB, giving a known relationship that aids breaking. Modern computer-based attacks can break Playfair quickly using simulated annealing or hill-climbing algorithms.