Playfair cipher — encrypt letter pairs with a keyword square

The Playfair cipher builds a 5×5 square from a keyword and encrypts the message two letters at a time using row, column and rectangle rules; enter the keyword and encrypt, or decrypt a Playfair message.

Live demo · real result from this tool
Direction

Result

BMODZBXDNABEKUDMUIXMMOUVIF

Processed on your device — nothing is uploaded.

How to use the Playfair cipher tool

  1. Choose the Direction: Encrypt or Decrypt.
  2. Enter the Keyword. Spaces and repeated letters in it are ignored; the default is “playfair example”.
  3. Type into Your text. When decrypting, the ciphertext must have an even number of letters.
  4. Copy the Result. It comes out in capital letters without spaces, as Playfair messages traditionally do.

What it does and when to use it

The Playfair cipher was invented by Charles Wheatstone in 1854 and named after Lord Playfair, who promoted it. It was the first well-known cipher to encrypt letters in pairs, which hides single-letter frequencies better than a simple substitution. That makes it a popular step up in cryptography classes and a regular in puzzle hunts.

It is still a classical cipher meant for puzzles and teaching, not for protecting data; a computer breaks it quickly. If you like square-based ciphers, the four-square cipher also works on pairs but uses two keyword squares, and the bifid cipher splits letters into coordinates. The plain Polybius square shows the grid on its own.

How it works

The square. The keyword’s letters fill a 5×5 grid in order, repeats skipped, with J counted as I. The rest of the alphabet follows. With “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

The pairs. Only letters are kept, in capitals. The message is split into pairs. When the two letters of a pair would be the same, an X goes between them (Q if the letter is X), and an odd final letter gets an X.

The rules for each pair:

  • Same row: each letter becomes the one to its right, wrapping round. Decryption goes left.
  • Same column: each letter becomes the one below it, wrapping round. Decryption goes up.
  • Rectangle: each letter is replaced by the letter in its own row but in the other letter’s column.

So HI, which forms a rectangle, becomes BM, and DE, in the same column, becomes OD. The tool does this in your browser.

Worked examples

Results from the tool:

Hide the gold in the tree stump   key playfair example   →  BMODZBXDNABEKUDMUIXMMOUVIF
instruments                       key monarchy           →  GATLMZCLRQXA
GATLMZCLRQXA                      key monarchy, Decrypt  →  INSTRUMENTSX
ABC                               decrypt                →  Playfair ciphertext has an even number of letters.

The first line is the well-known example; its decryption reads HIDETHEGOLDINTHETREXESTUMP, with an X between the two Es of “tree”. The third line shows the pad X left at the end of INSTRUMENTS. When decrypting, the tool also adds a reminder that filler letters remain and that I and J share a cell.

Limits and tips

  • Digits, spaces and punctuation are removed. Spell numbers out as words.
  • A pair is never encrypted to itself, and reversed pairs (AB and BA) give reversed results. Code breakers use both facts.

Frequently asked questions

Why is there an extra X in my decrypted message?
Playfair can only encrypt pairs of two different letters. Before encrypting, the tool puts an X between doubled letters in a pair, such as the two Es in tree, and adds an X at the end if the letter count is odd. Decryption cannot tell those fillers from real letters, so they stay in the result for you to remove.
What if the doubled letter is itself X?
Then the filler is Q instead, so XX is split as XQ XQ, and a final lone X is padded to XQ. This avoids creating another doubled pair.
Why does my result use I where I typed J?
The 5×5 square has 25 cells, so I and J share one. Every J is treated as I before encrypting, and decryption always gives I.
Some textbooks show a different answer for the same message. Why?
Playfair has small variations. Some books pad with Z or Q instead of X, drop Q instead of merging I and J, or split double letters differently. This tool uses X as the filler and merges I and J, as many modern references do. Make sure both sides use the same rules.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close