Appearance
The Playfair Cipher
Input Text:
Introduction
Initialization
- Create a
5 x 5
table populating each cell with a capital letter in alphabetical order, row-by-row, from left to right, as seen above. - Since the English alphabet has 26 capital letters and the table has only 25 cells, we need to pick a letter that will share the same cell. For example, we select the letter
J
. It will share the same cell as its previous letterI.
I
will be used for the mapping. If the letter isA
, thenZ
is used.
Secret Key
- Choose a random
Secret Key.
The letters you choose replace the starting letters of the starting cells in the table. All other unused letters fill the other cells. TheSecret Key
can't have duplicates. Try it out above.
Encryption Steps
Measure the length of the plaintext. If the value is odd, then pad the plaintext with the
Pad Letter
, e.g.,X
. ThePad Letter
must differ from theShare Letter.
Iterate through the plaintext, incrementing two letters at a time.
If both letters are the same, replace the second letter with the
Pad Letter
X
.If the letters appear on the same row, replace the letters with the ones to their right respectively. If the letter is under the last column, wrap around to the first column of the same row and use that letter.
If the letters appear under the same column, replace the letters with the ones below them respectively. If the letter is in the last row, wrap around to the first row under the same column and use that letter.
If the letters neither appear on the same row nor the same column, then pick the first letter of the pair and move to the same column of the second letter. Stay on the same row and use that letter. Do the same thing for the second of the pair. Move it to the same column of the first letter as the pair. Stay on the same row and use that letter.
Decryption Steps
Measure the length of the ciphertext. If the value is odd, then pad the ciphertext with the
Pad Letter
, e.g.,X
.Iterate through the ciphertext, incrementing two letters at a time.
If both letters are the same, replace the second letter with the
Pad Letter
X
.If the letters appear on the same row, replace the letters with the ones to their left respectively. If the letter is under the last column, wrap around to the last colum of the same row and use that letter.
If the letters appear under the same column, replace the letters with the ones above them respectively. If the letter is in the first row, wrap around to the last row under the same column and use that letter.
If the letters neither appear on the same row nor the same column, then pick the first letter of the pair and move to the same column of the second letter. Stay on the same row and use that letter. Do the same thing for the second of the pair. Move it to the same column of the first letter as the pair. Stay on the same row and use that letter. The order is the same as encryption.
Citations, References, and Links
- Wikipedia Contributors. (2023, November 24). Playfair cipher. Wikipedia; Wikimedia Foundation. https://en.wikipedia.org/wiki/Playfair_cipher