Playfair Cipher Encoder / Decoder

Security Client-side playfair cipher encryption decryption keyword digraph classical

This tool runs entirely client-side, in your browser: your data is never sent anywhere.

What it does

The Playfair cipher is a manual symmetric encryption technique invented in 1854 by Charles Wheatstone (and popularized by Lord Playfair). Unlike the Caesar cipher, which shifts one letter at a time, Playfair encrypts pairs of letters (digraphs), which makes basic frequency analysis much harder — a huge step up in security for a pen-and-paper cipher.

It works by arranging the alphabet (traditionally merging I and J into a single cell) into a 5×5 grid built from a keyword, then encrypting each letter pair according to the position of the two letters relative to each other in that grid.

Try it

How it works

  1. Build the key square — Write the keyword (duplicate letters and non-letters removed), followed by the remaining letters of the alphabet in order, into a 5×5 grid. I and J share the same cell.
  2. Prepare the plaintext — Remove all non-letter characters, convert JI, uppercase everything, then split it into pairs (digraphs). If both letters of a pair are the same, insert a filler letter (X, or Q if X is already the pair's letter) between them. If the text has an odd number of letters after this, append a trailing filler.
  3. Encrypt each pair according to where the two letters fall in the grid:
  1. Decrypt by reversing the rules: same-row shifts left, same-column shifts up, and rectangle swaps stay the same (since rectangle swapping is its own inverse).

Notes

Example

With the keyword PLAYFAIR, the key square is:

PLAYF
IRBCD
EGHKM
NOQST
UVWXZ

Encrypting HELLO WORLD (after removing the space and splitting into HE LX LO WO RL D → padded to HE LX LO WO RL DX) produces the ciphertext shown live above when you type it into the widget.