Playfair Cipher
Encrypt pairs of letters through a keyed 5×5 square using row, column, and rectangle rules.
What is the Playfair Cipher?
Playfair encrypts two letters at a time instead of one. A keyword builds a 5×5 square, normally combining I and J so 25 cells can represent the alphabet.
Each pair uses one of three geometric rules: same row, same column, or rectangle corners.
The cipher mechanics on this page are self-contained. Science Olympiad event formats, allowed variants, and tournament constraints can change by season; the current official Rules Manual and official clarifications take precedence.
No outside reference is assumed. Work through Foundations → Complete Reference → Encryption → Decryption in order, then use the competition and cryptanalysis sections.
What you need to know
- Build the square by writing the keyword without repeated letters, then the remaining alphabet.
- Treat I/J according to the convention given by the problem; this guide uses a combined I/J cell.
- Split plaintext into pairs. If a pair contains the same letter twice, insert a filler such as X between them. Add a filler if one letter remains at the end.
Beginner glossary
| Term | Meaning |
|---|---|
| Digraph | A pair of letters encrypted together. |
| Key square | A 5×5 alphabet square built from a keyword. |
| Filler | Usually X in this site; inserted to split repeated letters in a pair or pad an odd final letter. |
| Rectangle rule | For letters in different rows and columns, use the other corners of their rectangle. |
| I/J convention | A 5×5 English square needs one combined cell; this site combines I and J. |
Keep this beside you while solving
Example square using keyword CIPHER (I/J combined).
| Situation | Encryption rule | Decryption rule |
|---|---|---|
| Same row | Move each letter one cell right; wrap around. | Move each letter one cell left; wrap around. |
| Same column | Move each letter one cell down; wrap around. | Move each letter one cell up; wrap around. |
| Rectangle | Keep each row; take the other corner in the same row. | Same rectangle operation. |
Pair-preparation checklist
- Remove nonletters and convert J to I for this convention.
- Read left to right in pairs.
- If a pair would contain the same letter twice, insert X after the first letter and restart the pairing.
- If one letter remains at the end, append X.
Three geometry rules
| Geometry | Encrypt | Decrypt |
|---|---|---|
| Same row | Move each letter one cell right, wrapping. | Move each letter one cell left, wrapping. |
| Same column | Move each letter one cell down, wrapping. | Move each letter one cell up, wrapping. |
| Rectangle | Keep each letter’s row and take the other letter’s column. | The same rectangle operation reverses it. |
How encryption works
Prepare the text
Remove unsupported characters, split into pairs, and insert fillers when needed.
Locate both letters
Find the two cells in the 5×5 square.
Apply one rule
Same row → right; same column → down; rectangle → opposite corners.
Repeat
Process every pair independently.
How decryption works
Split ciphertext into pairs
Ciphertext length should be even.
Locate both cells
Use the same keyed square.
Reverse row/column moves
Left for same row, up for same column; rectangles use the same corner swap.
Interpret fillers
An X between doubled letters or at the end may be padding rather than literal plaintext.
How to approach it in Codebusters practice
- Keep the square visible while solving; repeatedly reconstructing it wastes time.
- Mark I/J convention clearly before starting.
- Work pair-by-pair and write intermediate plaintext under the ciphertext to reduce transcription errors.
What the problem gives you vs. what you produce
| Part | What to expect |
|---|---|
| You may be given | A keyword/key square and ciphertext, or plaintext to encrypt. |
| You must find | The opposite text by processing digraphs. |
| Fastest first move | Build and label the 5×5 square neatly; then handle pairs one at a time. |
How to attack an unknown or partially known key
- Playfair hides single-letter frequencies better than a simple substitution because it encrypts digraphs.
- Repeated digraphs and likely crib placements can still give structure.
- When the key/square is supplied, the task becomes deterministic; without it, cryptanalysis is substantially harder.
Follow one example from start to finish
CIPHER
HIDDEN CLUE → HI DX DE NC LU EX
HI → EP
(same row);
DX → BY
(rectangle).
EPBYFHGENSPZ
Before moving on, make sure you can answer these without another site:
- Can you explain what happens to the pair LL during preparation?
- Can you identify which rule applies to any two cells in the square?
- Can you reverse a same-row encrypted pair by moving left?
Common mistakes
Forgetting to split doubled letters in the same pair.
Forgetting end padding.
Moving the wrong direction during decryption.
Treating I and J as separate when the square combines them.
Competition speed strategies
Build the square neatly and label rows/columns mentally.
Circle each digraph as you finish it.
Check the geometry before moving letters; most errors are rule-selection errors, not arithmetic.
What to remember under time pressure
See every transformation
Use the lab to change inputs and keys, keep the relevant reference material visible, inspect each intermediate transformation, and then read the “How to reverse it” panel so encryption and decryption connect.