DEV Community

Cover image for Playfair Cipher Encryption Program In Python
Karan-Munjani
Karan-Munjani

Posted on • Updated on

Playfair Cipher Encryption Program In Python

In this post I'm going to explain you how to code playfair cipher to encrypt plaintext to cipher. So this post is all about encryption program and will soon add decryption program in this series also so stay tuned!

If you don't know how the algorithm works checkout previous post in this series.

So Without further ado, LET'S BEGIN!!👨‍💻👩‍💻

Can you recall what were the steps of algorithm?

Yes, You're right!
The Algorithm was consist of three steps:

  1. Convert plaintext into digraphs (i.e., into pair of two letters)
  2. Generate a Cipher Key Matrix
  3. Encrypt plaintext using Cipher Key Matrix and get ciphertext.

 

Programming Playfair Cipher:

Step: 1 Creating function to convert plaintext into digraphs

 

Step: 2 Function to generate a cipher key matrix

 

Now we need to locate index of particular character inside cipher key matrix to perform encryption:

 

Step: 3 Encrypt plaintext using cipher key matrix and get ciphertext

 

Final Step! Running our code from main method:

 

* * * * * * *

 

Thanks a lot for reading out!

I hope the code with comments was actually sufficient to understand the logic.

Here's the repository link to the whole code file GitHub Repo

But if you still have any doubts feel free to mention below in discussion section, I would love to answer them.

Also drop a heart ❤ if you gained some knowledge!

Top comments (2)

Collapse
 
sophyia profile image
Sophia Iroegbu

This is genuis. I was watching NCIS Hawi'i and wanted to try this, glad I found this.

Collapse
 
karanmunjani profile image
Karan-Munjani

Glad you find it useful..