Playfair Cipher

A classical, polygraphic cipher. Invented by Sir Charles Wheatstone in 1854. Named after Lord Playfair who promoted its use in diplomatic communication. The first digram substitution cipher, encrypting pairs of letters (bigrams) rather than single letters.

Key Space

The key is the arrangement of the 25 symbols in the grid, with I and J sharing 1 cell. The key space has 25!≈28425! \approx 2^{84} possible grids. A keyword is only 1 method for selecting a grid and does not cover every arrangement.

Encryption

Key Grid

A 5x5 grid holding the 25 letters of the English alphabet, treating I and J as one letter.

Construction:

  • Write a secret keyword with no repeating letters into the grid, starting from the top left, row by row.
  • Fill the remaining cells with the unused letters in alphabetical order.
PANTH
ERBCD
FGI/JKL
MOQSU
VWXYZ
Key grid from PANTHER.

Preparation

Steps:

  • Remove non-letters. Replace J with I. Uppercase the text.
  • Split the plaintext into bigrams from left to right.
  • If a bigram has 2 identical letters, insert a filler letter (XX, or QQ) between them and re-split.
  • If the plaintext length is odd, append a filler letter to the last bigram.
  • Encrypt each bigram by 1 of the 3 rules below.

Bigram Rules

  • Same row
    Replace each letter with the letter to its right, wrapping from the last column to the first.
  • Same column
    Replace each letter with the letter below it, wrapping from the last row to the first.
  • Rectangle
    The 2 letters sit at opposite corners of a rectangle. Replace each with the letter on its own row at the other corner.

No plaintext letter encrypts to itself.

Decryption

The receiver builds the same grid from the keyword and splits the ciphertext into bigrams. Each rule is inverted.

  • Same row
    Replace each letter with the letter to its left, wrapping from the first column to the last.
  • Same column
    Replace each letter with the letter above it, wrapping from the first row to the last.
  • Rectangle
    The same swap as encryption, each letter taken to the other corner on its own row.

Filler letters are spotted and dropped by reading the recovered plaintext.

Attacking

The unit of substitution is the bigram, so a monogram frequency count of the ciphertext is close to uniform.

Weaknesses that a cryptanalyst exploits:

  • 600 bigrams carry an uneven frequency distribution, led by TH, HE, AN, IN. A long ciphertext still leaks this structure.
  • A bigram and its reverse encrypt to a ciphertext bigram and its reverse. Plaintext pairs like RE and ER are detectable.
  • A digram never contains a repeated letter, so ciphertext bigrams like LL never appear.

Steps for a ciphertext-only attack:

  • Count ciphertext bigram frequencies and match the top ones against expected language bigrams.
  • Guess a probable word (a crib) and place it against repeated ciphertext stretches.
  • Each correct guess fixes relative positions of letters in the grid, as a row, column, or rectangle constraint.
  • Propagate the constraints, filling the grid, and confirm against the rest of the ciphertext.

Known-plaintext attacks are far stronger. A few matched bigrams pin enough letters to reconstruct the grid, since the keyword layout is highly constrained.

Worked Example

Plaintext wakandaforever under keyword PANTHER.

Solution Reveal Hide

The grid built from PANTHER:

PANTH
ERBCD
FGI/JKL
MOQSU
VWXYZ
Key grid from PANTHER.

Same Row

ER RB

Move each letter 1 cell right.

Same Column

WA AR

Move each letter 1 cell down.

Rectangle

KA GT

Take the other corner on the same row.

Pair encryption in the PANTHER key grid.

Positions are (row,column)(\text{row}, \text{column}) with both starting at 00.

wakandaforever has 14 letters. No bigram repeats a letter, and the length is already even, so no filler is needed.

WA KA ND AF OR EV ER

Encrypt each bigram by its rule.

BigramPositionsRuleMappingResult
WAW(4,1)W(4,1), A(0,1)A(0,1)Same columnW→(0,1)=AW \to (0,1) = A, A→(1,1)=RA \to (1,1) = RAR
KAK(2,3)K(2,3), A(0,1)A(0,1)RectangleK→(2,1)=GK \to (2,1) = G, A→(0,3)=TA \to (0,3) = TGT
NDN(0,2)N(0,2), D(1,4)D(1,4)RectangleN→(0,4)=HN \to (0,4) = H, D→(1,2)=BD \to (1,2) = BHB
AFA(0,1)A(0,1), F(2,0)F(2,0)RectangleA→(0,0)=PA \to (0,0) = P, F→(2,1)=GF \to (2,1) = GPG
ORO(3,1)O(3,1), R(1,1)R(1,1)Same columnO→(4,1)=WO \to (4,1) = W, R→(2,1)=GR \to (2,1) = GWG
EVE(1,0)E(1,0), V(4,0)V(4,0)Same columnE→(2,0)=FE \to (2,0) = F, V→(0,0)=PV \to (0,0) = PFP
ERE(1,0)E(1,0), R(1,1)R(1,1)Same rowE→(1,1)=RE \to (1,1) = R, R→(1,2)=BR \to (1,2) = BRB

Ciphertext is ARGTHBPGWGFPRB.

Decryption reverses each rule under the same grid.

BigramPositionsRuleMappingResult
ARA(0,1)A(0,1), R(1,1)R(1,1)Same column, shift upA→(4,1)=WA \to (4,1) = W, R→(0,1)=AR \to (0,1) = AWA
GTG(2,1)G(2,1), T(0,3)T(0,3)RectangleG→(2,3)=KG \to (2,3) = K, T→(0,1)=AT \to (0,1) = AKA
HBH(0,4)H(0,4), B(1,2)B(1,2)RectangleH→(0,2)=NH \to (0,2) = N, B→(1,4)=DB \to (1,4) = DND
PGP(0,0)P(0,0), G(2,1)G(2,1)RectangleP→(0,1)=AP \to (0,1) = A, G→(2,0)=FG \to (2,0) = FAF
WGW(4,1)W(4,1), G(2,1)G(2,1)Same column, shift upW→(3,1)=OW \to (3,1) = O, G→(1,1)=RG \to (1,1) = ROR
FPF(2,0)F(2,0), P(0,0)P(0,0)Same column, shift upF→(1,0)=EF \to (1,0) = E, P→(4,0)=VP \to (4,0) = VEV
RBR(1,1)R(1,1), B(1,2)B(1,2)Same row, shift leftR→(1,0)=ER \to (1,0) = E, B→(1,1)=RB \to (1,1) = RER

Recovered text is wakandaforever.

A known-plaintext attack uses 3 matched bigrams from the run above, with the grid unknown.

Plaintext waorka
Ciphertext ARWGGT
Matched bigrams are WA/AR, OR/WG, and KA/GT.
  • wa to AR. Testing the same-row rule for w,a fails to reproduce AR, but the same-column rule holds: shifting each letter 1 row down (wrapping) turns w into a and a into r. So w, a, r sit in the same column, in that cyclic order.
  • or to WG. The same-column rule holds again: shifting o and r 1 row down (wrapping) gives w and g. Since w was already placed in the shared column from the previous bigram, this extends it to o, w, a, r, g, in cyclic order.
  • ka to GT. Testing the same-row and same-column rules both fail, so the bigram is a rectangle: the cell sharing k’s row and a’s column is g, and the cell sharing a’s row and k’s column is t. Since g was already placed in the shared column above, this confirms a’s column is the same one.

More matched bigrams pin the remaining letters the same way. Once most cells are known, the alphabetical order of the trailing letters exposes the keyword, and the full grid follows.

Written by October 27, 2026 6 min read
Was this helpful?