Playfair Cipher Encoder and Decoder
Type a keyword and a message, and this page builds the 5x5 Playfair square, splits the text into digraphs and enciphers each one, naming the rule that moved it: same row, same column, or the rectangle the two letters make. BALLOON under the key MONARCHY comes out IBSUPMNA, and you can step through the four digraphs with their path lit up on the square. What most Playfair pages leave out is what the cipher threw away, so this one counts it on screen: the characters that were not letters and were dropped, the J read as I, the filler pushed between a doubled pair, and the pad on an odd tail. Decoding IBSUPMNA with the same key returns BALXLOON, filler and all, because nothing can tell a filler from a real letter. The letters that sit where a filler would sit are marked, and never removed.
BALLOON -> BA LX LO ON
the doubled L is split by the filler X
- BA -> IBsame column
- LX -> SUrectangle, filler
- LO -> PMrectangle
- ON -> NAsame row
Playfair enciphers two letters at a time, so it works on letters only: spaces, punctuation, digits and accented letters are dropped before it starts, J is read as I, a doubled pair is separated by the filler and an odd count is padded. This text: 1 filler X inserted between a doubled letter. That is why a decode hands back the padded letters rather than your sentence.
The keyed square
The key goes in first, letter by letter, skipping any letter already placed; the rest of the alphabet follows. I and J share one cell, which is how 26 letters fit 25 places. Step through the digraphs to see the path each one takes.
| M | O | N | A | R |
| C | H | Y | B | D |
| E | F | G | I/J | K |
| L | P | Q | S | T |
| U | V | W | X | Z |
Digraph 1 of 4: BA becomes IB
Both letters sit in column 4, so each moves one place down, wrapping from the bottom of the column back to the top.
Three worked examples
Common questions
- How does the Playfair cipher work?
- It enciphers two letters at a time against a 5x5 square. The keyword goes in first, letter by letter, with any repeat skipped, and the rest of the alphabet follows, so the key MONARCHY gives the rows M O N A R, C H Y B D, E F G I K, L P Q S T and U V W X Z. The message is then split into pairs, and each pair follows one of three rules. Two letters in the same row each move one place to the right, wrapping from the end of the row back to the start. Two in the same column each move one place down, wrapping from the bottom back to the top. Otherwise the two letters are opposite corners of a rectangle, and each takes the letter in its own row at the other letter's column. BALLOON becomes the pairs BA, LX, LO and ON, which encipher to IB, SU, PM and NA: IBSUPMNA.
- Why does decoding not give me my original message back?
- Because Playfair throws things away before it enciphers anything. Decode IBSUPMNA with the key MONARCHY and you get BALXLOON, not BALLOON. The X was pushed in to separate the doubled L, and on the way back the cipher has no way to tell that X from a letter you actually typed, so this tool leaves it in and marks it instead of guessing. The same goes for the spaces and punctuation it dropped and for every J it read as I. Taking the marked letters out is the reader's job, and it is the one step of Playfair that is judgement rather than arithmetic.
- Why is there an X in the middle of my text?
- A digraph of two identical letters has no rule on the square, so a filler is pushed between them: BALLOON is paired BA, LX, LO, ON rather than BA, LL, OO, N. An odd number of letters also leaves the last one without a partner, so the same filler pads the end. X is the usual choice, Q and Z are both in print, and all three are on the Filler control. If the doubled letter is itself the filler, as in XX, the tool falls back to the next letter on that list, so it never tries to separate two X with another X.
- What happens to the letter J?
- It becomes I. A 5x5 grid has 25 cells, so the square holds 25 letters and two of the alphabet's 26 have to share one; the classical choice, and the one used here, is I and J. The square draws that cell as I/J and the Merge readout says so beside the result. It means JAM and IAM encipher identically, and a decode hands back I every time: JULY comes back as IULY, and you put the J in by reading it.
- What happens to spaces, punctuation and capital letters?
- They are dropped before pairing, because the square has nowhere to put them. Case is not part of the cipher either, so lower case comes back upper: balloon and BALLOON both encipher to IBSUPMNA. Digits, accented letters such as é, other alphabets and emoji all go the way of a space. The page counts everything it dropped for the text in the box, so you can see exactly how much of the message the ciphertext is not carrying, and why word breaks never survive a round trip.
- Can the marked filler letters be wrong?
- Yes, which is exactly why they are marked rather than removed. A letter is flagged when it sits where a filler sits: second in its pair, and either between two copies of one letter or on the very end. EXES fits that description perfectly. It enciphers to IUIL under MONARCHY and deciphers back to EXES with no filler involved at all, and the X in the middle is still flagged, because from the shape of the text alone it cannot be told apart from one. The flag is a guess about English; the cipher underneath it is not.
- Is the Playfair cipher secure?
- No, and it has not been for a long time. Charles Wheatstone invented it in 1854 and it carries the name of Lord Playfair, who promoted it; armies used it in the field through the Boer War and both world wars because it needs nothing but a pencil. Frequency analysis on digraphs breaks it with a few hundred letters of ciphertext, and a computer does that instantly. It is a fine cipher for puzzles, escape rooms, classrooms and homework, and anything that genuinely has to stay private wants modern encryption.
- Is anything I type sent to a server?
- No. The square, the digraphs and the result are all worked out in your browser, and nothing is uploaded. The message, key, direction and filler are kept in this browser so the page comes back as you left it, and the Clear button beside Copy and Swap empties the box, puts the key and filler back to their defaults and deletes that saved record. There is no account and no sign-up. Text up to 20,000 characters is enciphered whole, and past that the page asks for a shorter passage instead of quietly cutting it.
An exact reproduction of the classical 5x5 Playfair rules, with I and J sharing a square and the filler you chose visible in the digraph trace. Decryption returns the padded text and not your original: the cipher cannot tell a filler from a real letter, so BALXLOON comes back and you take the X out yourself. This is a historical cipher for teaching and puzzles and offers no real security.