The Playfair cipher, Wheatstone-Playfair cipher, or Playfair square is a polygraphic substitution cipher. It was invented in 1854 by the English inventor Charles Wheatstone. It was popularized by the Scottish scientist and parliamentarian Lord Lyon Playfair.
Playfair has been trying for many years to use this cipher in war. His idea was repeatedly opposed. The British Ministry of War finally used it during the Boer War. It was then used by all warring parties during both world wars. Like other ciphers of this period, with the advent of the computer age, it was withdrawn from use due to the possibility of breaking with the use of brute force attacks, finding the most common digrams in a given language.
Encoding with Playfair cipher replaces the plaintext letter pairs with another letter pair.
It consists of a code table with 25 letters of the Latin alphabet. Due to the fact that the Latin alphabet contains 26 letters, the one letter that is least used in the alphabet is removed or the letters are used alternatively (eg I instead of J). We also enter a keyword or keywords into the table. The repeated letters are removed. We fill the rest of the table fields with the remaining letters of the alphabet in alphabetical order.
For example, setting the keyword as KLUCZ and removing the letter Q, the code table would look like this:
K L U C Z
A B D E F
G H I J M
N O P R S
T V W X Y
To encrypt the plaintext, we divide it into digrams consisting of pairs of letters. If the explicit word does not have an even number of letters, then at the end we add the letter X. If there are the same letters in a pair, we separate them also with the letter X. For example, if we want to encode the word CALCOOLATOR , we divide them into pairs CA LC OX OL AT OR . We added an X between the letters OO to separate a pair of the same letters.
Then we find the first pair of letters CA
K L U C Z
A B D E F
G H I J M
N O P R S
T V W X Y
Now we read letters from the intersection of lines drawn vertically and horizontally from each open letter.
K L U C Z
A B D E F
G H I J M
N O P R S
T V W X Y
The first encoded letter pair of CA of the plaintext will be KE .
If a pair of letters appear on the same line, then for each open letter we read the letter immediately to its right. If, however, a pair of letters appear in the same column, then for each open letter we read the letter directly below it. An example here is another pair of letters LC of our word, located on the same line of the code table, which after encoding looks like UZ.
K LUCZ
A B D E F
G H I J M
N O P R S
T V W X Y
We repeat the reading operation for each of the pairs of clear word letters CA LC OX OL AT OR and assign it pairs read from the code table KE UZ RT PK GK PS.
More on: Wikipedia - Playfair cipher