🎭 Playfair Cipher

Encrypt and decrypt text with the Playfair cipher. Uses a 5x5 key square and digraph substitution.

About the Playfair Cipher

The Playfair cipher, invented in 1854 by Charles Wheatstone and promoted by Lord Playfair, was the first practical digraph substitution cipher. Instead of substituting single letters, it encrypts pairs of letters using a 5x5 key square, making frequency analysis much harder. It was used militarily by the British in the Boer War and World War I. This tool runs entirely in your browser — nothing is uploaded.

How it works

  • Build the square — The key (with duplicates removed) fills the matrix first, followed by the remaining letters of the alphabet. I and J share a single cell.
  • Prepare the text — Letters are uppercased, J becomes I, non-letters are dropped, and the text is split into pairs. Doubled letters in a pair are separated by an X; an odd final letter is padded with X.
  • Encrypt — Same row: shift right. Same column: shift down. Otherwise: swap columns (rectangle rule).
  • Decrypt — Reverse direction: shift left, shift up, or rectangle rule.

Use cases

  • Studying classical manual ciphers and digraph substitution.
  • Creating puzzles, geocaches, or escape-room challenges.
  • Understanding why polygraphic ciphers resist simple frequency analysis.
  • Demonstrating historical military cryptography.

Frequently asked questions

Is the Playfair cipher secure? No. It can be broken with known-plaintext or hill-climbing attacks. Use it for learning and fun, not for real secrets.

What happens to J? J is treated as I and shares the same cell, since a 5x5 grid holds only 25 of the 26 letters.

Why do I see X in the output? X is used as a filler to separate identical letters in a pair and to pad an odd-length message.

Does this tool upload my text? No. All encryption and decryption happens locally in your browser.