How to use the playfair cipher tool
- Choose Encrypt or Decrypt.
- Enter the key phrase. Only letters count, repeated letters are dropped, and J is treated as I.
- Type the message. For encryption, spaces, digits and punctuation are removed. For decryption, paste the ciphertext.
- Read the result, the key square and the table of letter pairs. Optionally change the filler letter used between double letters.
Formula
Key square: the key letters without repeats, then the rest of the alphabet, in a 5 x 5 grid with I and J together
Same row: each letter is replaced by the one to its right (left to decrypt), wrapping around
Same column: each letter is replaced by the one below (above to decrypt), wrapping around
Rectangle: each letter is replaced by the one in its own row and the other letter's column
Before encrypting, the message is cut into pairs. A pair of equal letters gets the filler between them, and an odd last letter gets the filler added.
The classic key PLAYFAIR EXAMPLE
With the key PLAYFAIR EXAMPLE the square has the rows PLAYF, IREXM, BCDGH, KNOQS and TUVWZ. The message HIDE THE GOLD IN THE TREE STUMP becomes the pairs HI DE TH EG OL DI NT HE TR EX ES TU MP (the double E gets an X between), and the ciphertext is BMODZBXDNABEKUDMUIXMMOUVIF. Decrypting it returns HIDETHEGOLDINTHETREXESTUMP, with the filler X still in place.
With the key MONARCHY, the message INSTRUMENTS becomes the pairs IN ST RU ME NT SX and the ciphertext GATLMZCLRQXA, where the final X was added to complete the last pair.
How Playfair works
Playfair was one of the first ciphers to work on pairs of letters instead of single letters. Because a letter is replaced differently depending on its partner, simple letter counting does not work as easily as for a Caesar cipher. It was used by armies in the early twentieth century for short field messages, since the key square is easy to memorize and use without any equipment.
The method has quirks. J and I share a cell, so J is read as I. An X, or another filler, is added between double letters and at the end, and it stays in the decrypted text; you have to remove it by eye. The ciphertext never contains a pair of identical letters, which helps in breaking it.
Learning and puzzles
Use it to learn how substitution ciphers grow stronger, or to build puzzles. A Playfair message is far more work to break by hand than a Caesar shift, but computers break it easily by trying likely keys and scoring the text. It must not be used for anything that needs real privacy.
To study letter patterns in a ciphertext, use the letter frequency counter. To compare with a simple shift, try the Caesar cipher; for a message turned into dots and dashes, the Morse code translator; and for a transposition cipher, the rail fence cipher tool.
Assumptions and limits
- The square has 25 cells, so J and I share one and the message is read with J as I.
- The filler letter is X unless you choose Q or Z. If the pair is already the filler, Q is used.
- Decrypted text keeps its fillers and has no spaces.
- The message can be up to 3,000 characters.
Frequently asked questions
What is the Playfair cipher?
A digraph cipher from the nineteenth century that encrypts pairs of letters using a 5 by 5 square built from a key phrase.
Why is there an X in my decrypted message?
It is the filler that was added to split a double letter or to fill the last pair. Remove it when reading.
What happens to J?
It is merged with I, so both use the same cell in the square.
Is Playfair secure?
No. It is stronger than a simple shift but is easily broken with a computer, so use it only for puzzles and teaching.