The Playfair Cipher was invented by Sir Charles Wheatstone, but gains its name from Lyon Playfair, who popularised its use. It is a very simple block cipher, encrypting digraphs (pairs of letters) in the plaintext, rather than single characters, at a time.
The first stage of encryption is to select a key. In this case, the key is the arrangement of 25 letters of the alphabet (J is excluded) in a 5x5 grid. These can be a completely random permutation (more secure, but still easily broken) or by writing out a keyword or keyphrase, followed by the remaining letters, in order. In this case, we shall choose the keyphrase "Playfair Cipher", giving the key as:
P L A Y F I R C H E B D G K M N O Q S T U V W X Z
The first stage of encryption is to prepare the plaintext. This requires two stages, the first being to replace all J's with letter "I". Secondly, split the text up into digraphs, and working through one at a time, if there is a double-letter, insert an "X" between them. Note when this happens you will have to re-pair all subsequent letters. If there is now an odd number of characters, append an "X" to the end of the message. Once this has been completed you can proceed with the main algorithm.
Working through one digraph at a time, apply the corresponding rule below:
- If both letters occur in the same row in the key, they are replaced by the letter to the immediate right of each one. If one letter is at the end of the row, it is replaced by the one at the beginning (i.e. it wraps around).
- If both letters occur in the same column in the key, they are replaced by the letter immediately below each one. If one letter is at the bottom of the column, it is replaced by the letter at the top (again, wrapping around).
- If the letters are neither in the same row nor column, then they will necessarily create a rectangle in the key. The letters are enciphered using the other letter on same horizontal line of the rectangle (i.e. the letter in the same row as the plaintext character being enciphered, and the same column as the other plaintext character of the digraph).
Using the example key above, the plaintext
ANY CIPHERTEXT WITHOUT A J IS LIKELY TO BE ENCIPHERED USING THIS ALGORITHM
when encrypted becomes
PQ AH BI EI EO HZ QZ EN RS ZN PC HN PR MH AF NQ MI IT HR YI IC RM XN BU MQ ER QY AD VD EN EK
Breaking the Cipher
Today, computers can crack this cipher in a very short time using a hill-climbing algorithm. This starts with a random key and uses this decrypt the text. Next, small changes are made to the key such as swapping rows / columns / letters around, and for each of these the text is decrypted again. If this text is a more likely candidate than the previous text, then the new key is taken for the start of the next round of permutations. How good a piece of text is can be determined by comparing the frequency distribution with that of a standard piece of text in the given language you're decrypting to. Eventually, no better match is found and it is then likely (though not guaranteed) that you have found the exact decryption.
Although it is possible with computers with ease, the cipher can still be cracked by hand, although it takes a bit more effort. Several techniques can be employed to help gain a foothold into breaking the cipher. First, digraph frequencies can be compared in a similar way as single-letter frequency analysis, although modified tables have to be used due to the lack of J's in the message, and the superfluous X's.
Other tricks include noting that if a pair of letters appear changed in the plaintext, then the ciphertext digraphs will also be swapped. E.g. if "AT" enciphers to "GD" then "TA" will encipher to "DG". If some words can be guessed at then these can also be used to help place key letters, although you have to consider all three possibilies for placement (same row, same column or neither). To reduce this, try to find pairs of plaintext-ciphertext digraphs with a common letter between them. E.g. "AT" and "TK", since this tells you that A and T must appear in the same row or column adjacent to one another. With perseverance, the cipher is crackable, given a long enough ciphertext.