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.
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.
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 (, or ) 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
REandERare detectable. - A digram never contains a repeated letter, so ciphertext bigrams like
LLnever 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.
The grid built from PANTHER:
P A N T H
E R B C D
F G I K L
M O Q S U
V W X Y Z
Positions are with both starting at .
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.
WA: and share column . . . GivesAR.KA: and form a rectangle. . . GivesGT.ND: and form a rectangle. . . GivesHB.AF: and form a rectangle. . . GivesPG.OR: and share column . . . GivesWG.EV: and share column . . . GivesFP.ER: and share row . . . GivesRB.
Ciphertext is ARGTHBPGWGFPRB.
Decryption reverses each rule under the same grid.
AR: column , shift up. . . GivesWA.GT: rectangle. . . GivesKA.HB: rectangle. . . GivesND.PG: rectangle. . . GivesAF.WG: column , shift up. . . GivesOR.FP: column , shift up. . . GivesEV.RB: row , shift left. . . GivesER.
Recovered text is wakandaforever.
A known-plaintext attack uses 3 matched bigrams from the run above, with the grid unknown.
plaintext: wa or ka
ciphertext: AR WG GT
watoAR. Testing the same-row rule forw,afails to reproduceAR, but the same-column rule holds: shifting each letter 1 row down (wrapping) turnswintoaandaintor. Sow,a,rsit in the same column, in that cyclic order.ortoWG. The same-column rule holds again: shiftingoandr1 row down (wrapping) giveswandg. Sincewwas already placed in the shared column from the previous bigram, this extends it too,w,a,r,g, in cyclic order.katoGT. Testing the same-row and same-column rules both fail, so the bigram is a rectangle: the cell sharingk’s row anda’s column isg, and the cell sharinga’s row andk’s column ist. Sincegwas already placed in the shared column above, this confirmsa’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.