CrosswordPrint Free crossword maker and word puzzle tools

Playfair Cipher Decoder and Encoder

Enter a keyword and your text. The Playfair square, the pairs and the result appear as you type, with the rule used for each pair.

The Playfair square

Keyword letters come first (shaded), then the rest of the alphabet. Tap or hover a pair in the table below to see its letters in the square.

Crack it without the key

Put Playfair cipher text in the box at the top. The tool first tries every English word and every pair of common words as the keyword, which solves most puzzle ciphers in a second or two. For an unknown scrambled square it can then run a longer search; that needs about 150 letters or more and can fail. Everything runs in your browser.

Playfair Cipher Worksheet

Name: ____________________      Date: ______________

Keyword:

Message:

Write the answer here:

The Playfair cipher tool encrypts and decrypts text with the Playfair cipher, a substitution cipher that works on pairs of letters and uses a square built from a keyword. It is free and runs entirely in your browser. No sign-up is needed, and nothing you type is sent to a server. Enter a keyword, choose a square size, and the result updates as you type, along with the 5×5 Playfair square (the key matrix) itself. The step table shows the rule for every pair, which makes it a handy way to learn playfair encryption, and Find the Key can often decrypt a message without the keyword.

Playfair cipher example

How to use the Playfair Cipher tool

  1. Choose Encrypt or Decrypt.
  2. Type your key into the Keyword box. The keyword letters are shaded in the square shown on the page.
  3. Open the Square menu and pick one of the options: 5×5, I and J share a cell (the default), 5×5, Q left out, or 6×6, A–Z and 0–9.
  4. Check the Filler letter. It is X by default.
  5. Type or paste your text. The output updates as you type.
  6. Choose how to display the result under Show result as: One string (the default), Pairs, or Groups of five.
  7. When decrypting, leave Tidy the decrypted text ticked to remove filler letters between doubled letters and at the end. Untick it to see the raw text.
  8. Read the step table under the result to see every pair, the rule used, and the result. Tap a row to highlight its cells in the square. The table shows the first 80 pairs.

Try an Example loads a sample so you can see the tool working. Copy Result copies the output, and Use Result as Input moves it into the input box. Clear empties the fields. Print Worksheet prints the keyword, the square, the cipher text, and lines for your answer. Your settings are saved in the address bar, so you can bookmark or share a link that reopens them. Worksheets are free to use, including commercially.

What is the Playfair cipher and how does it work?

The Playfair cipher is a pair-based cipher invented by Charles Wheatstone in 1854. It was named after Lord Playfair, who promoted it. It was the first well-known digraph cipher, meaning it encrypts two letters at a time rather than one.

To build the square, write the keyword letters left to right without repeats. Then fill the rest of the square with the remaining alphabet in order. J is left out and treated as I, so the square holds 25 letters. Prepare your message by removing everything except letters, changing J to I, and splitting the text into pairs. If both letters in a pair are the same, insert the filler X between them. If one letter is left over at the end, add an X. If a pair would be XX, use Q as the filler instead. For example, “balloon” becomes BA LX LO ON.

Each pair is encrypted by one of three rules:

  • Same row: each letter is replaced by the letter to its right, wrapping around to the start of the row.
  • Same column: each letter is replaced by the letter below it, wrapping around to the top.
  • Rectangle: if the letters are in different rows and columns, each letter is replaced by the letter in its own row that sits in the other letter’s column.

How to decrypt a Playfair cipher with the key

Build the same square from the keyword. Split the cipher text into pairs. If the cipher text has an odd number of letters, or a pair of identical letters, it is not valid Playfair. Reverse the rules: in the row rule, move left instead of right, and in the column rule, move up instead of down. The rectangle rule stays the same.

In the worked example, the keyword “playfair example” gives this square:

PLAYF IREXM BCDGH KNOQS TUVWZ

The message “Hide the gold in the tree stump” is prepared as HI DE TH EG OL DI NT HE TR EX ES TU MP. Pair DE uses the column rule and becomes OD. Pairs EX and TU use the row rule. Decrypting the cipher text returns HIDETHEGOLDINTHETREXESTUMP. With Tidy turned on, the X between the two Es is removed, giving HIDETHEGOLDINTHETREESTUMP.

Frequently asked questions

Why is J missing from the Playfair square?

The square has 25 cells, and the alphabet has 26 letters. Dropping J lets all the other letters fit in a 5×5 grid. J is treated as I, so a message that uses J will decrypt as I. The 6×6 option avoids this by including all 26 letters and the digits 0–9.

What are the X fillers in a Playfair cipher?

X is the letter added to split a doubled pair, such as the two Ls in “balloon,” and to complete an odd-length message. If a pair would be XX, Q is used instead. You can change the filler under Filler letter.

How do I decrypt a Playfair cipher without the key?

Enter at least 20 letters of cipher text and press Find the Key. The tool first tries each word in its 54,000-word list, and pairs of common words, as the keyword. It scores each result for English. In tests, this found the right keyword in 30 out of 30 runs using texts of 40 to 160 letters. If the key is not a dictionary word and the text has 150 or more letters, a slower search tries random squares in 5-second runs. It worked about 30% of the time at 150 letters and 65–70% of the time at 200–300 letters. It can fail on short texts. Use Use this key above to copy a key you find into the form.

Why does my decrypted text have extra X letters?

Those Xs are fillers the encryption added between doubled letters or at the end. Tidy removes them automatically. A real X in the original message can also be removed by mistake, so check the raw output when Tidy is on.

What does “not valid Playfair” mean?

The tool shows this message when the cipher text has an odd number of letters or contains a pair of identical letters. Playfair encryption never produces either, so the text was either not made with this cipher or it has been changed.

Is the Playfair cipher secure today?

No. Its letter pairs leak patterns, and with enough cipher text it can be broken without the key. It is useful for learning how pair-based ciphers work and for puzzles, not for protecting real secrets.

Can I use the printed worksheets for commercial purposes, such as Amazon KDP or Etsy?

Yes. Worksheets and coded messages you make here are free to use for any purpose, including classroom packs, escape-room kits, KDP puzzle books and Etsy printables, royalty-free and with no attribution needed. The only limit is that you may not copy the tool itself to run a competing service.

  • Polybius Square: Use it to encrypt letters as coordinate pairs in a grid, which is an earlier idea behind pair-based ciphers.
  • Rail Fence Cipher: Use it to scramble a message by writing it in a zigzag across rails.
  • Cipher Identifier: Use it when you have a message and want to guess which cipher made it.
  • Caesar Cipher: Use it for a simple shift cipher that moves each letter a fixed number of places.
  • Atbash Cipher: Use it to reverse the alphabet, so A becomes Z and B becomes Y.
  • Cryptogram Solver: Use it to work through a substitution puzzle where each letter stands for another.
  • Pigpen Cipher: Use it to convert letters into symbols taken from a grid pattern.

About the Playfair cipher

The Playfair cipher or Playfair square or Wheatstone–Playfair cipher is a manual symmetric encryption technique and was the first literal digram substitution cipher. The scheme was invented in 1854 by Charles Wheatstone, but bears the name of Lord Playfair for promoting its use.

The technique encrypts pairs of letters (bigrams or digrams), instead of single letters as in the simple substitution cipher and rather more complex Vigenère cipher systems then in use. The Playfair cipher is thus significantly harder to break since the frequency analysis used for simple substitution ciphers does not work with it. The frequency analysis of bigrams is possible, but considerably more difficult. With 600 possible bigrams rather than the 26 possible monograms (single symbols, usually letters in this context), a considerably larger cipher text is required in order to be useful.

History

The Playfair cipher was the first cipher to encrypt pairs of letters in cryptologic history. Wheatstone invented the cipher for secrecy in telegraphy, but it carries the name of his friend Lord Playfair, first Baron Playfair of St. Andrews, who promoted its use. The first recorded description of the Playfair cipher was in a document signed by Wheatstone on 26 March 1854.

It was initially rejected by the British Foreign Office when it was developed because of its perceived complexity. Wheatstone offered to demonstrate that three out of four boys in a nearby school could learn to use it in 15 minutes, but the Under Secretary of the Foreign Office responded, "That is very possible, but you could never teach it to attachés."

It was however later used for tactical purposes by British forces in the Second Boer War and in World War I and for the same purpose by the British and Australians during World War II. This was because Playfair is reasonably fast to use and requires no special equipment - just a pencil and some paper. A typical scenario for Playfair use was to protect important but non-critical secrets during actual combat e.g. the fact that an artillery barrage of smoke shells would commence within 30 minutes to cover soldiers' advance towards the next objective. By the time enemy cryptanalysts could decode such messages hours later, such information would be useless to them because it was no longer relevant.

During World War II, the Government of New Zealand used it for communication among New Zealand, the Chatham Islands, and the coastwatchers in the Pacific Islands. Coastwatchers established by Royal Australian Navy Intelligence also used this cipher.

Description

The Playfair cipher uses a 5 × 5 table containing a key word or phrase. Memorization of the keyword and 4 simple rules was all that was required to create the 5 by 5 table and use the cipher.

To generate the key table, one would first fill in the spaces in the table (a modified Polybius square) with the letters of the keyword (dropping any duplicate letters), then fill the remaining spaces with the rest of the letters of the alphabet in order (usually omitting "J" or "Q" to reduce the alphabet to fit; other versions put both "I" and "J" in the same space). The key can be written in the top rows of the table, from left to right, or in some other pattern, such as a spiral beginning in the upper-left-hand corner and ending in the center. The keyword together with the conventions for filling in the 5 by 5 table constitute the cipher key.

To encrypt a message, one would break the message into digrams (groups of 2 letters) such that, for example, "HelloWorld" becomes "HE LL OW OR LD". These digrams will be substituted using the key table. Since encryption requires pairs of letters, messages with an odd number of characters usually append an uncommon letter, such as "X", to complete the final digram. The two letters of the digram are considered opposite corners of a rectangle in the key table. To perform the substitution, apply the following 4 rules, in order, to each pair of letters in the plaintext:

If both letters are the same (or only one letter is left), add an "X" after the first letter. Encrypt the new pair and continue. Some variants of Playfair use "Q" instead of "X", but any letter, itself uncommon as a repeated pair, will do.

If the letters appear on the same row of your table, replace them with the letters to their immediate right respectively (wrapping around to the left side of the row if a letter in the original pair was on the right side of the row).

Example

Using "playfair example" as the key (assuming that I and J are interchangeable), the table becomes (omitted letters in red):

The first step of encrypting the message "hide the gold in the tree stump" is to convert it to the pairs of letters "HI DE TH EG OL DI NT HE TR EX ES TU MP" (with the null "X" used to separate the repeated "E"s). Then:

Thus the message "hide the gold in the tree stump" becomes "BM OD ZB XD NA BE KU DM UI XM MO UV IF", which may be restructured as "BMODZ BXDNA BEKUD MUIXM MOUVI F" for ease of reading the cipher text.

Text adapted from the Wikipedia article “Playfair cipher” (revision 1357286810, 2026-06-01), authors, licensed under CC BY-SA 4.0. Shortened: some sections and paragraphs were left out, and reference markers, images and templates were removed; wording is otherwise unchanged. This text remains available under the same licence.

Updated