Skip to content

The Playfair Cipher


   



 

Input Text:

 

Introduction

Initialization

  1. 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.
  2. 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 letter I. I will be used for the mapping. If the letter is A, then Z is used.

Secret Key

  1. 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. The Secret Key can't have duplicates. Try it out above.

Encryption Steps

  1. Measure the length of the plaintext. If the value is odd, then pad the plaintext with the Pad Letter, e.g., X. The Pad Letter must differ from the Share Letter.

  2. Iterate through the plaintext, incrementing two letters at a time.

  3. If both letters are the same, replace the second letter with the Pad Letter X.

  4. 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.

  5. 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.

  6. 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

  1. Measure the length of the ciphertext. If the value is odd, then pad the ciphertext with the Pad Letter, e.g., X.

  2. Iterate through the ciphertext, incrementing two letters at a time.

  3. If both letters are the same, replace the second letter with the Pad Letter X.

  4. 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.

  5. 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.

  6. 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.