Guide
The Playfair cipher: encrypting letter pairs with a 5×5 square
The Playfair cipher was the first practical cipher to encrypt pairs of letters instead of single letters. That hides the simple letter frequencies that break substitution ciphers like Caesar and Atbash, which made it a useful field cipher for over half a century. This tool builds the key square, prepares the pairs and applies the rules, showing every step so you can follow along or check work done by hand.
Building the key square
Write the keyword’s letters into a 5×5 grid, row by row, skipping any letter already used, then fill the remaining cells with the rest of the alphabet in order. A 5×5 grid has 25 cells, so one letter must go: by default J is written as I and shares its cell; alternatively Q, the rarest English letter, is left out. With the keyword PLAYFAIR EXAMPLE, the square begins P L A Y F / I R E X M.
Preparing the message
The message is written in capitals without spaces and split into pairs. A pair may not contain the same letter twice, so a filler — normally X — is inserted between doubled letters: “tree” becomes TR EX E… If the message ends with a single letter, a filler is added. When the filler would itself be doubled, the alternative filler is used instead. The prepared pairs are shown under the square.
The three rules
For each pair, find both letters in the square. If they are in the same row, replace each with the letter to its right, wrapping around to the start of the row. If they are in the same column, replace each with the letter below, wrapping to the top. Otherwise they form the corners of a rectangle: replace each with the letter in its own row at the other letter’s column. The well-known example “Hide the gold in the tree stump” with this key encrypts to BMODZBXDNABEKUDMUIXMMOUVIF.
Decrypting
Decryption applies the rules in reverse: left instead of right, up instead of down; the rectangle rule is unchanged. The result still contains the fillers and has I in place of J, because that information was removed when the message was prepared. Remove stray Xs while reading.
Strengths and weaknesses
Encrypting pairs gives 600 possible digraphs instead of 26 letters, which defeats simple frequency counting. But common pairs such as TH, HE and IN still show through, a letter never encrypts to itself, and a reversed pair encrypts to the reversed result. With enough text, Playfair is broken by hand; computers do it in seconds. It is ideal for teaching and puzzles.
Private
Everything runs in your browser.
A worked example
With the key square for PLAYFAIR EXAMPLE, the pair HI is a rectangle case: H is in row 3, column 5 and I in row 2, column 1. Each letter is replaced by the letter in its own row at the other’s column, giving B and M, so HI becomes BM. The pair DE has D and E in the same column, so each moves down one row: D becomes O and E becomes D, giving OD. These are the first two pairs of the classic example, BM OD ZB.
Related tools
Try a keyword cipher with the Vigenère Cipher, coordinates in a square with the Tap Code Translator, transposition with the Rail Fence Cipher, or start simple with the Caesar Cipher Solver.
Checked against the current version of the Playfair Cipher on .

