The Playfair cipher is a substitution cipher that encrypts pairs of letters (digraphs) instead of single letters. It was invented in 1854 by Charles Wheatstone and was used by the British in the Boer War and World War I. By working with letter pairs, it avoids some of the weaknesses of simple single-letter substitution.
Imagine a 5×5 grid of letters — like a treasure map. A keyword determines how the grid is arranged. To encrypt, you take your message two letters at a time, find both letters on the grid, and follow three simple rules based on their positions to find the encoded pair. The grid is the key to everything.
The 5×5 grid built from the keyword. Letters I and J share the same cell (a common convention, since we need 25 cells for 26 letters).
Each pair of plaintext letters is transformed according to three rules based on their position in the grid.
For each pair of letters, find them in the grid and apply the rule that matches their positions:
A standard substitution cipher replaces one letter at a time, so the letter E always becomes the same ciphertext letter. This makes it vulnerable to frequency analysis.
The Playfair cipher encrypts pairs of letters, so the same letter can produce different ciphertext depending on what letter it is paired with. The pair HE encrypts differently from HA or HO. This makes single-letter frequency analysis useless, though the cipher can still be broken with enough ciphertext by analyzing digraph frequencies.
Disclaimer: these pages are educational demos provided as-is, with no warranty of any kind. The author is not responsible for any consequences arising from their use.
Send comments and bug reports to chris@chrisspackman.com.
Version 0.1 — Last updated: 2026-02-21
This page is Copyright © 2025 – 2026
Chris Spackman <chris@chrisspackman.com>.
This web site developed entirely on GNU/Linux with Free / Open Source Software.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.