Playfair Cipher

The Playfair cipher encrypts letters in pairs using a 5x5 key square, so Hide the gold in the tree stump with the key playfair example becomes BMODZBXDNABEKUDMUIXMMOUVIF.

Input

Using key PLAYFAIREXAMPLE. J counts as I. Ignored 1 character that is not A to Z.

Direction

Letters only. J counts as I. Same letters in a pair get an X between them.

Encoded with key PLAYFAIREXAMPLE

Key square

Key square for key PLAYFAIREXAMPLE. I and J share one cell.
PLAYF
I/JREXM
BCDGH
KNOQS
TUVWZ

How your text was split

Type some text to see its pairs.

Why use our Playfair Cipher?

Encode and Decode with a Keyword

Type a keyword and the square is built as you type, then your text is encoded or decoded one letter pair at a time. The key starts as playfair example, so the example above works at once.

Every Pair with Its Rule

The pair list shows what each pair became and whether the same row, same column or rectangle rule did it. Pick a pair to see its letters marked in the key square; the first 60 pairs are listed.

Private, Nothing Saved

Encoding and decoding run in your browser; nothing you type is sent. Nothing is saved either, so the message is gone when you close the tab.

What is the Playfair Cipher?

The Playfair cipher is a substitution cipher that encrypts letters two at a time instead of one by one. A keyword fills a 5x5 square of letters, the message is split into pairs, and each pair is swapped for two other letters by where they sit in the square. Working in pairs hides the single letter counts that give simpler ciphers away.

This page shows each step instead of only the answer: the key square for your keyword, how your text was split into pairs, the X fillers that were added and the rule used for every pair. That makes it useful for checking a worked example by hand, and for sending or reading a message with a keyword you already know.

Who Invented It: Wheatstone, 1854

  • Inventor:Charles Wheatstone invented it in 1854; it bears the name of Lord Playfair, who promoted its use.
  • First record:The first recorded description is in a document Wheatstone signed on 26 March 1854 (Wikipedia, NKU, Wheatstone).
  • Pairs first:It was the first cipher to encrypt pairs of letters, unlike the single letters of simple substitution and the more complex Vigenere cipher of the time.
  • In wartime:British forces used it in the Second Boer War and World War I, and British and Australian forces in World War II.
  • Security today:It has been regarded as insecure since before World War I, so it suits puzzles and study rather than real secrets.

Common Use Cases

Cryptography Homework

Check a hand-worked answer pair by pair: the key square and the rule list show where your square or a pair differs.

Classroom Demonstrations

Change the keyword in front of a class and the square, the pairs and the output all update at once.

Keyword Puzzles

Encode a clue with a keyword hidden somewhere else in the game, so players must find the key before they can read it.

Reading a Received Message

Decode a message from a friend or a puzzle when you know the keyword, then remove the fillers by reading.

Comparing Keywords

Encode the same sentence with two keywords and compare the squares and outputs side by side in two tabs.

History of Codes

Compare it with the Caesar cipher, which shifts single letters, to see what working in pairs changes.

How to Use the Playfair Cipher Decoder

1

Enter the keyword

Type the keyword into Key. It starts as playfair example, and only the letters A to Z in it count.

2

Add your text

Type or paste your text into Text. Spaces, digits and punctuation are dropped, and J is read as I.

3

Choose a direction

Press Encode or Decode. The output updates as you type, and its heading names the key in use.

4

Read the pairs and copy

Read the pair list to see the rule behind each pair, then copy the output.

Decrypting: What Comes Back

Rules Run Backwards

Decoding runs the rules backwards: left, up, and the same rectangle. Both sides need the same keyword.

Fillers and J Stay

Fillers and J as I stay in the output: BMODZBXDNABEKUDMUIXMMOUVIF decodes to HIDETHEGOLDINTHETREXESTUMP, with letter 20 listed as a likely filler.

Likely Fillers Listed

After decoding, the status line names the positions of likely fillers: an X between two equal letters or at the end, or a Q after an X.

Read Before You Delete

Drop a filler only where it makes no sense, which takes a reader. The decoder lists fillers but never removes one for you.

Spot Playfair Text

Encrypted text never holds a pair of the same letter, a quick way to spot Playfair. Paste one and the decoder names the pair that breaks the rule.

Odd Letter Left as Is

Encoded text always has an even number of letters. If the last letter has no partner, it is copied unchanged and the status line says so.

Splitting Text into Pairs: X Fillers and J

  • •Digraphs: Each digraph (letter pair) is encrypted as one unit; spaces, digits and punctuation are dropped.
  • •Fillers: If both letters of a pair match, X goes between them; an odd last letter gets X; Q is used when the letter is X. BALLOON gives BA LX LO ON.
  • •Letters only: Hide the gold in the tree stump loses its 6 spaces and is split into 13 pairs.
  • •J as I: J is read as I before the split; when encoding, the How your text was split card counts how often that happened.

Try the Playfair Cipher with Your Own Keyword

Change the keyword, paste a message and watch the square, the pairs and the output change together. Encoding a short sentence on paper next to the tool is a quick way to learn the three rules.

When you decode, use the keyword exactly as the sender did and read the result before deleting any X. The decoder cannot tell a filler from a real letter, so that last step is yours.

Building the 5x5 Key Square

Keyword First

Write the keyword letters first, dropping repeats, then the rest of the alphabet.

25 Cells

J shares the I cell, so the Playfair square holds 25 letters. The Key square card above shows that cell as I/J.

The Example Key

The key playfair example gives the rows PLAYF IREXM BCDGH KNOQS TUVWZ (Wikipedia).

The Three Rules, with a Worked Example

Same Row

Same row: take the letter to the right of each, wrapping around.

Same Column

Same column: take the letter below each, wrapping around.

Rectangle

Otherwise, a rectangle: each letter takes the one in its own row and the other letter's column.

In this Playfair cipher example, the 13 pairs of Hide the gold in the tree stump use the rectangle 10 times, the same row 2 times and the same column 1 time.

Every pair of Hide the gold in the tree stump with the key playfair example
PairBecomesRule
HIBMrectangle
DEODsame column
THZBrectangle
EGXDrectangle
OLNArectangle
DIBErectangle
NTKUrectangle
HEDMrectangle
TRUIrectangle
EXXMsame row
ESMOrectangle
TUUVsame row
MPIFrectangle

Related tools

Frequently Asked Questions

How does the Playfair cipher work?

It builds a 5x5 square from a keyword, splits the message into letter pairs and replaces each pair by the same row, same column or rectangle rule.

Who invented the Playfair cipher?

Charles Wheatstone invented it in 1854. It is named after his friend Lord Playfair, who promoted its use.

Why is there an X in my decrypted text?

X is the filler added between doubled letters and at an odd end. Decoding keeps every filler and lists the likely ones; you remove them by reading.

What happens to the letter J?

J shares the I cell of the square, so it is encrypted as I and comes back as I: JAM encodes to EPIM and decodes to IAMX.

Can you decrypt Playfair without the keyword?

Not with this tool; it needs the keyword. Solvers without it work from how often letter pairs appear.

Is Playfair stronger than a Caesar cipher?

Yes, because it works on pairs and hides single letter counts, but it has been regarded as insecure since before World War I.