Playfair Cipher Encrypt & Decrypt

Digraph substitution using a 5×5 keyword-keyed square.

Ad placeholder (leaderboard)

The Playfair cipher was the first practical digraph substitution cipher, encrypting pairs of letters at a time instead of single letters. Invented in 1854 and named after Lord Playfair, it was used for tactical military messages because it could be performed by hand yet resisted casual frequency analysis. This tool builds the keyword square and applies the real rules in your browser.

How it works

First build a 5×5 square: write the keyword (dropping repeats) into the grid, then fill the remaining cells with the rest of the alphabet. Because the grid has 25 cells, I and J share one cell.

Split the plaintext into pairs. If a pair would contain two identical letters, insert an X between them; if the message has an odd length, pad the final letter with X. Then apply three rules to each pair:

  • Same row: replace each letter with the one immediately to its right, wrapping around.
  • Same column: replace each letter with the one immediately below it, wrapping around.
  • Rectangle: replace each letter with the one in its own row at the other letter’s column.

Decryption uses the same rules but shifts left and up instead of right and down.

Example

With the keyword MONARCHY, the digraph IN encrypts to a new pair determined by their rectangle in the square. Repeated letters such as the pair in BALLOON are split with X (BA LX LO ON) before encryption.

Notes

Decrypted output may contain padding X letters that you can usually remove by reading in context. Since I and J share a cell, a decrypted I might represent a J — again resolved by context.

Ad placeholder (rectangle)