UTILS.
100% in-browser
🔠

Playfair Cipher Encoder / Decoder

Encode or decode text with the classic Playfair digraph cipher using a 5x5 keyword square, with automatic X-padding and the key square shown.


    

I and J share one cell; J is treated as I.

output

About this tool

The Playfair Cipher tool encrypts and decrypts text with Charles Wheatstone's 1854 digraph cipher, the first practical cipher to encrypt pairs of letters instead of single letters. It works from a 5x5 key square built from a keyword: the keyword's unique letters are written first (I and J share one cell), then the rest of the alphabet fills the remaining squares. This tool shows the generated square so you can follow every step.

To encrypt, the plaintext is upper-cased, J is replaced with I, and the letters are split into digraphs (pairs). A filler letter (X by default) is inserted between a doubled pair and appended if the text has an odd length. Each digraph is then transformed by three rules: two letters in the same row are each replaced by the letter to their right (wrapping around); two in the same column by the letter below (wrapping); and any other pair forms a rectangle, where each letter is replaced by the one in its own row but the other letter's column. Decoding applies the same rules in reverse (left / up / same rectangle).

Everything runs locally in your browser with nothing uploaded, so your messages stay private. Note that Playfair merges I/J and pads with a filler, so decoded text may contain stray X's or an I where a J belonged — these are normal artifacts of the cipher, not errors.

Frequently asked questions

How is the Playfair key square built?
Write the keyword with duplicate letters removed, then append the remaining letters of the alphabet in order. Because the grid holds only 25 cells, I and J are merged into one cell, giving a 5x5 square that maps each letter to a row and column.
Why does the output contain extra X's?
Playfair cannot encrypt a pair of identical letters, so an X (the filler) is inserted between them, and a lone final letter is padded with X to complete the last pair. These fillers are not automatically stripped on decode, so you may see stray X's in decrypted text.
What happens to the letter J?
The standard 5x5 square has no room for a separate J, so J is treated as I both when building the square and when preparing the text. Decrypted messages that originally contained J will show I in its place.
How are the three digraph rules applied?
Same row: replace each letter with the one to its right (wrap at the edge). Same column: replace with the one below (wrap). Rectangle: each letter keeps its own row but takes the other letter's column. Decoding shifts left and up instead of right and down.

More tools