Playfair Cipher
Encode and decode the Playfair cipher with a keyword of your choice. Switch between the I/J and no-Q square variants, follow along on the interactive 5×5 key square, and copy, download, or share the result. Everything runs in your browser.
I and J share one cell, so the square holds 25 letters. Any J in your text is treated as I. This is the most common convention.
Enter text above to see the result here.
Key square (5×5)
The keyword fills the grid first, in highlighted cells, then the rest of the alphabet completes it. Every digraph is enciphered by locating its two letters on this square.
How to use Playfair Cipher
- 1
Choose encode or decode
Pick Encode to turn plain text into Playfair ciphertext, or Decode to turn ciphertext back into the prepared plain text using the same keyword.
- 2
Pick a square variant
Choose the common I/J variant, where I and J share a cell, or the no-Q variant, where Q is left out. A short hint explains how each one builds the 25-letter square.
- 3
Enter your keyword
Type a keyword such as MONARCHY. Its distinct letters fill the 5×5 key square first, and the highlighted cells below update instantly to show your grid.
- 4
Type or paste your text
Enter your message and the cipher runs as you type. Letters are paired and enciphered, doubled pairs are split with a filler, and spaces, digits, and punctuation are removed.
- 5
Copy, download, or share
Copy the result, download it as a text file, or share a link that reopens the tool with your exact keyword, text, and settings ready to go.
Understanding the Playfair Cipher
What is the Playfair cipher?
The Playfair cipher is a manual symmetric encryption technique and the first cipher in history to encrypt pairs of letters instead of single letters. Working on digraphs, two-letter blocks, rather than one letter at a time, flattens the single-letter frequency pattern that breaks simple substitution ciphers, so for its era Playfair was both strong and quick enough to use by hand in the field.
It was invented by the British scientist Charles Wheatstone in 1854 but takes its name from his friend Lord Playfair, who promoted its use to the British government and military. Today it is a classic teaching cipher and a favourite in puzzles, escape rooms, and capture-the-flag challenges, because it is rich enough to be interesting yet simple enough to work by hand.
Building the 5×5 key square
Everything in Playfair revolves around a 5×5 grid of 25 letters built from a secret keyword. You write the distinct letters of the keyword into the grid first, skipping any repeats, and then fill the remaining cells with the rest of the alphabet in order. Because 26 letters cannot fit into 25 cells, one letter has to share or be dropped: in the most common convention I and J share a single cell, while an alternative convention simply leaves Q out.
The keyword scrambles the alphabet into an order only someone with the keyword can reproduce, and the tool above highlights the keyword letters so you can see exactly how your grid is laid out. With the keyword MONARCHY, for example, the first row becomes M O N A R, and the alphabet then continues from where the keyword leaves off.
The three Playfair rules
Before enciphering, the message is split into pairs of letters. If a pair would be a double letter, such as the LL in BALLOON, a filler letter X is inserted to break it up, and if the message has an odd number of letters a final filler is added so every pair is complete. Spaces, digits, and punctuation are removed first, because there is nowhere to put them on the square.
Each pair is then enciphered with one of three rules based on where its two letters sit. If both letters are in the same row, each is replaced by the letter immediately to its right, wrapping around to the start of the row. If both are in the same column, each is replaced by the letter immediately below, wrapping to the top. Otherwise the two letters form the corners of a rectangle, and each is replaced by the letter in its own row at the other letter's column.
A worked Playfair example
Take the keyword PLAYFAIR EXAMPLE and the message HIDE THE GOLD IN THE TREE STUMP. The key square becomes P L A Y F on the first row, then I R E X M, B C D G H, K N O Q S, and T U V W Z. The message splits into the pairs HI DE TH EG OL DI NT HE TR EX ES TU MP, where an X has been inserted to break the double E in TREE.
The first pair HI forms a rectangle, so H becomes B and I becomes M, giving BM. Working through every pair the same way produces the ciphertext BM OD ZB XD NA BE KU DM UI XM MO UV IF. Decrypting it with the same keyword reverses each rule and returns HIDETHEGOLDINTHETREXESTUMP, the prepared message with its inserted X still in place.
Decrypting a Playfair cipher
Decryption uses the very same key square and simply runs the rules backwards. For two letters in the same row you move left instead of right, and for the same column you move up instead of down; the rectangle rule is its own mirror image, so it is unchanged. Choose Decode above, enter the keyword that was used to encrypt, and paste the ciphertext to recover the message.
One quirk is worth remembering: because letters are folded together, doubled pairs are split, and odd messages are padded, the decrypted text is the prepared message rather than the exact original. You will sometimes see a stray X or Z between repeated letters or at the very end, and a J that was merged into I stays as I. Readers remove these by eye, which is normal for Playfair and not a fault of the tool.
A short history of the Playfair cipher
Charles Wheatstone first described the cipher in 1854, and Lord Playfair demonstrated it to senior figures including Prince Albert and the future Prime Minister Lord Palmerston. The British War Office at first thought it too complicated, but its real strength was that it needed no tables or apparatus, only a memorised keyword, which made it ideal for officers in the field.
It saw genuine service for decades. British forces used it in the Second Boer War and in the First World War, and it was still employed for low-level traffic in the Second World War, including by Australian coastwatchers in the Pacific. Its value was tactical: a message only needed to stay secret for the hours or days during which the information it carried still mattered.
How secure is the Playfair cipher?
By modern standards Playfair is not secure, but it is far tougher than a simple substitution cipher. Because it enciphers 600 possible digraphs rather than 26 letters, a plain frequency count of single letters gives nothing away, and an attacker must instead analyse the frequencies of letter pairs. With a few hundred characters of ciphertext, known techniques such as digraph frequency analysis and hill-climbing with simulated annealing can recover the key.
That makes Playfair a wonderful educational and recreational cipher: strong enough to show why pair-based encryption was a real advance, yet weak enough to break as a puzzle. For any genuine need to protect information you should use a modern, peer-reviewed algorithm such as AES instead.
Frequently asked questions
What is the Playfair cipher?
How does the Playfair cipher work?
What is the 5×5 key square?
What are the three Playfair rules?
Why does Playfair insert X or Z between letters?
What is the difference between the I/J and no-Q variants?
Can you show a worked Playfair example?
How do you decrypt a Playfair cipher?
Who invented the Playfair cipher?
How do you break or crack the Playfair cipher?
Does the Playfair cipher keep spaces, numbers, and punctuation?
Is my text uploaded to a server?
Related tools
Keep going with these handy tools