Playfair

History

The Playfair cipher was invented by the English physicist and inventor Sir Charles Wheatstone (1802-1875) in 1854 and was promoted by a close friend of Wheatstone, the Scottish scientist and politician Baron Lyon Playfair (1818-1898), after whom it is named.

Description

The cipher is created using a 5 x 5 square matrix filled with a keyed alphabet using all the letters of the alphabet, with J being replaced by I. If a 6 x 6 square matrix is selected the letters of the alphabet and numbers 0-9 are used with A followed by 1, B by 2, C by 3 and so on up to J followed by 0. A keyed alphabet is created from a keyword, with repeated letters being omitted, followed by the unused letters of the alphabet in alphabetical order. For example the keyword PLAYFAIR is reduced to PLAYFIR when repeated letters are removed. Appending unused alphabet letters produces the keyed alphabet:

PLAYFIRBCDEGHKMNOQSTUVWXZ

The keyed alphabet is written into the matrix in a selected route, e.g. horizontal, diagonal or clockwise.

P L A Y F

I R B C D

E G H K M

N O Q S T

U V W X Z

Encryption is performed by separating the plaintext into pairs of letters or digraphs. If a pair contains identical letters a null letter, such as X, is inserted between them. If the plaintext contains an odd number of letters a null letter is also added at the end of the text to complete the last letter pair. The two letters of each pair are located in the matrix and are enciphered using one of the following rules:

  1. If the two letters are in the same row take the two letters to the right of the plaintext letters with the last column wrapping around to the first column. So letters in the last column are replaced by letters in the first column.

  2. If the two letters are in the same column take the two letters below the plaintext letters with the last row wrapping around to the first row. So letters in the last row are replaced by letters in the first row.

  3. If the two letters are on different rows and columns treat them as being in the corners of a rectangle and take the two letters in the other corners, beginning with the letter on the same row as the first plaintext letter.

Example

For example, encipher the following Mark Twain quote "Be careful about reading health books. You may die of a misprint.” using the key word PLAYFAIR gives:

Plaintext: be ca re fu la bo ut re ad in gh ea lt hb ox ok sy ou ma yd ie of am is pr in tx

Ciphertext: IH BY IG PZ AY RQ ZN IG FB EU HK HP FO QH SV SG XC NV HF FC EN TL FH CN LI EU SZ

Solving

Solving methods: Hill Climbing and Dictionary keyword search.

Both 5x5 and 6x6 Playfair solvers have been implemented. The square size is determined automatically depending on whether the cipher contains any numbers.