Playfair Cipher

Playfair Cipher is a #Monoalphabetic Cipher #algorithm invented by Charles Wheatstone in 1854, that encrypts two letters (digram) at once instead of encrypts only one letter. It is resilient against Frequency Analysis since there are 676 digrams to analyse (\(26 \times 26\)) therefore more ciphertext needed to crack. However, given enough amount of letters, it could be easily cracked especially after computer was invented since it still retains much of plaintext structure.

In Playfair Cipher, a \(5 \times 5\) matrix is needed to store the key. First, we fill in the letters of keyword without duplications, then we fill rest of the entry with other alphabets. The following matrix is built with a keyword “NEEDY”:

NEDYA
BCFGH
I/JKLMO
PQRST
UVWXZ

Note: Both I and J are always belonged to the same entry in the matrix.

Using the built matrix, we can now encrypt and decrypt the message by follows the steps below:

  • Divide the plaintext into two letters each.
  • If a pair is a repeated letter or it is a single letter, add filter letter ‘x’.
  • If both letters fall in the same row, replace each with the letter to the right (wrap back to the left most of the row from the right end).
  • If both letters fall in the same column, replace each with the letter below it (wrap back to the top most of the column from the bottom end).
  • Otherwise, each letter is replaced by the one in its row in the column of the other letter of the pair (mirror replacement).
#cryptography #algorithm