Skip to content

Playfair Cipher

Enter a keyword and a message, and the tool builds the 5 × 5 key square, splits the message into pairs and enciphers each pair, showing which of the three Playfair rules it used. Decoding works the same way in reverse, with likely filler letters marked for you to remove.

Mode

Its letters fill the square first, each used once; the rest of the alphabet follows in order.

Fitting 26 letters into 25 cells

Splits a doubled letter (BALLOON → BA LX LO ON) and pads an odd last letter. When the letter to split is the filler itself, a stand-in is used: Q for X (Z if the square has no Q), and X for Z or Q.

Cipher text

BM OD ZB XD NA BE KU DM UI XM MO UV IF

Key square and pairs

  • Same row: each letter is replaced by the one to its right, wrapping to the start of the row.
  • Same column: each letter is replaced by the one below it, wrapping to the top.
  • Anywhere else: the two letters mark opposite corners of a rectangle, and each is replaced by the corner in its own row.
PLAYF
IREXM
BCDGH
KNOQS
TUVWZ

Select a pair in the table to see it in the square: its letters are shaded blue and the letters they become amber.

Prepared message: HI DE TH EG OL DI NT HE TR EX ES TU MP

PairRuleResult
RectangleBM
Same columnOD
RectangleZB
RectangleXD
RectangleNA
RectangleBE
RectangleKU
RectangleDM
RectangleUI
filler addedSame rowXM
RectangleMO
Same rowUV
RectangleIF

How to Use the Playfair Cipher

  1. 1. Choose a mode and a keyword. The keyword's letters fill the square first, each once; the rest of the alphabet follows in order.
  2. 2. Decide how 26 letters fit into 25 cells. Most sources merge I and J; some leave out Q instead. Sender and receiver must use the same square.
  3. 3. Type the message. Only letters count — spaces, digits and punctuation are dropped — and the result comes back in capitals, in pairs.
  4. 4. Follow the pairs. Select any pair in the table to see its letters, and the letters they become, highlighted in the square.
  5. 5. Tidy up after decoding. The fillers added during encoding come back in the plain text. The tool highlights likely fillers; delete the ones that do not belong.

How the Playfair Cipher Works

Playfair enciphers letters two at a time, which is what made it a real step beyond simple substitution. Everything happens in a 5 × 5 square: write the keyword into it row by row, skipping any letter already used, then fill the remaining cells with the rest of the alphabet in order. With the keyword PLAYFAIR EXAMPLE and I merged with J, the square is:

Key square for PLAYFAIR EXAMPLE

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

Preparing the message

Keep only the letters, write J as I, and split the text into pairs, or digraphs. Two rules make sure every pair holds two different letters. A doubled letter inside a pair is split by a filler, usually X, so BALLOON is prepared as BA LX LO ON. An odd letter left at the end is padded with the filler. When the letter being split is X itself, a second filler stands in — this tool uses Q, or Z when Q is not in the square.

The three rules

  • Same row: replace each letter with the one to its right, wrapping from the end of the row back to the start. In the square above, EX becomes XM.
  • Same column: replace each letter with the one below it, wrapping from the bottom back to the top. DE becomes OD.
  • Rectangle: otherwise the two letters sit at opposite corners of a rectangle, and each is replaced by the corner in its own row. HI becomes BM.

Decoding uses the same square with the first two rules reversed: move left instead of right, and up instead of down. The rectangle rule undoes itself.

Worked Example

This is the classic textbook example, and the tool's sample. With the square above, Hide the gold in the tree stump is prepared as HI DE TH EG OL DI NT HE TR EX ES TU MP — the X splits the double E of TREE — and enciphers to BMODZBXDNABEKUDMUIXMMOUVIF. Decoding gives back HIDETHEGOLDINTHETREXESTUMP, and the reader has to see that the X in TREXESTUMP is a filler and drop it. X is also a real letter, so the tool marks the X it suspects and leaves the decision to you.

Who Invented the Playfair Cipher?

Charles Wheatstone, the physicist and inventor, devised the cipher in 1854, but it carries the name of his friend Lyon Playfair, the Scottish scientist and politician who promoted it to the British government. It needed nothing but a pencil and a memorised keyword, and it resisted the frequency counting that broke simple substitution, so it suited tactical use: the British army used it in the Second Boer War and the First World War, and British and Australian forces still used it for low-level messages in the Second World War.

Breaking Playfair, and Why It Is No Longer Secure

Enciphering pairs flattens the single-letter statistics: there are 600 possible digraphs rather than 26 letters, and the same letter enciphers differently depending on its partner. But Playfair leaks structure. No pair ever holds a doubled letter; a pair and its reverse encipher to reversed results, so if AB becomes XY then BA becomes YX; and no letter ever enciphers to itself. With enough cipher text, common digraphs such as TH and HE reveal parts of the square, and a guessed word fills in the rest. Joseph Mauborgne of the US Army published a method of solution in 1914, and today a computer search recovers the square from a few hundred letters.

Frequently Asked Questions

What is the Playfair cipher?
A hand cipher that encrypts pairs of letters using a 5 × 5 square built from a keyword. Each pair is replaced according to where its letters sit — in the same row, in the same column, or at the corners of a rectangle. Charles Wheatstone invented it in 1854, and it is named after Lyon Playfair, who championed it.
Why are I and J combined in Playfair?
The square has 25 cells and the alphabet has 26 letters, so one letter has to go. Merging I and J is the usual choice, because J is rare and a J written as I is easy to read in context. Some versions leave out Q instead and keep I and J separate; the tool offers both, and both sides must use the same one.
What happens to double letters in Playfair?
A pair made of one letter twice cannot be enciphered by the rules, so a filler — normally X — goes between them: BALLOON is prepared as BA LX LO ON. A doubled letter that straddles two pairs, like the OO in BO OK, needs no filler.
How do I remove the X when decoding Playfair?
Read the decoded text and delete each X that sits between two identical letters or at the very end, where it was added as padding — TREXESTUMP becomes TREESTUMP. The tool highlights the likely ones, but check each: a genuine X can sit between two equal letters too, as in EXECUTE.
Is the Playfair cipher secure?
Not by any modern standard. It hides single-letter frequencies, but digraph frequencies, its no-doubles and reversal patterns, and a few guessed words let a cryptanalyst rebuild the square, and software does it automatically from a few hundred letters. Treat it as a classic to learn from, not as protection.
How is Playfair different from the Vigenère cipher?
Vigenère shifts single letters by a repeating keyword, so the same letter enciphers differently at different positions — it is polyalphabetic. Playfair substitutes whole pairs from a fixed square, so it is digraphic — and both were broken long before computers.

Related Tools

More in Codes & Ciphers

See all Codes & Ciphers