playfair Cipher

1 minute read

playfair Cipher Using Python

What is the playfair Cipher?

It is one of the encryption techniques.
Playfair cipher is the first and best-known digraph substitution cipher, which uses the technique of symmetry encryption.

Who it works?

For example, the key is alphabet( categorical not numeric), So if the entered key is “mo” and the plain text is “hussein”. First we need to create a key_matrix to generate the encryped message from it. so we pur the letters in an array five * five that hold all the english letters. we starts to fill the key matrix by the key and we must care about not repetting the letters. after insetting the key we must fill the key_matrix by the rest of the letters. then we must divide the plain text to pairs. Considering if the letters are the same in one pairs we must put ‘x’ after the first one and if there is one letter lest we must put ‘x’after it. After preparing the key and the message, we start encryption. there are three techniques for the encrytption and decryption. Firdt one if the pair is in the same raw, we must shift the two letters right. if they are in the same column, we must shift them down. is they are not in the same raw or column, we take the interseption of the fist one with the second and vice versa. :-

For More Information About Playfair Cipher Playfair Cipher

What do you find in this script?

in this script you can :-
1- Encrypt a message
3- Decrypt an encrypted message

Python Code



Screenshots From Run

How to run this script?

  • Install python

    Download the latest version of python python

  • install termcolor

    pip install termcolor

Whole Code On GitHub


Thanks ☺♥