Playfair Cipher Explained: Rules, Grid and Example

The Playfair cipher is a classical encryption method that replaces pairs of letters rather than encrypting each letter on its own. A keyword creates a 5×5 letter square, and rules based on the letters' positions in that square determine each encrypted pair.

How the Playfair key square is built

Write the keyword first, keeping only the first occurrence of each letter. Then add the remaining alphabet letters in order. The traditional square has 25 cells, so I and J share one cell. The keyword and the convention for combining I and J must match when encrypting and decrypting.

For example, the keyword CIPHER starts the square with C, I/J, P, H and E. The remaining unused letters fill the rest of the 5×5 grid.

Prepare the message as letter pairs

Remove spaces and punctuation for the classical process, then split the plaintext into digraphs. If a pair contains the same letter twice, insert a filler—often X—between them. If one letter remains at the end, add a filler to complete the final pair. These choices affect the ciphertext and how the plaintext is reconstructed.

The three encryption rules

  1. Same row: replace each letter with the letter immediately to its right, wrapping to the row's start when necessary.
  2. Same column: replace each letter with the letter immediately below it, wrapping to the top of the column.
  3. Rectangle: replace each letter with the letter in its own row and the other letter's column.

Decryption reverses the row and column directions; the rectangle rule uses the same corner swap. After decrypting, remove filler letters only when the original message makes their role clear.

What the Playfair cipher can and cannot protect

Encrypting pairs hides single-letter frequencies better than a simple substitution cipher, which makes Playfair useful for studying the evolution of cryptography. It is still a historical cipher with a small key square and well-known analytical weaknesses. It is not suitable for protecting modern messages or sensitive data.

Try the interactive demonstration

Use a sample message and keyword to inspect the generated grid and see how each pair is transformed in the Securnix Playfair cipher tool. For another classical method, read the Caesar cipher guide, or continue to the RSA encryption guide.

Learn Playfair Cipher