What is Encryption?
In very simple words, Encryption is a process of taking a plain text, it can be any message, email, or any text, combining with a key, and generating a cipher text which is hard to decode. Hence, encryption is the process of hiding plain text and making it unreadable to the outside user.
What is Decryption?
so, In simple terms, Decryption means deciphering the cipher text generated by the encryption algorithm into the original plain text.
Substitution Techniques | Encryption Algorithms
A substitution technique is one in which the letters of plaintext are replaced by other letters or by numbers or symbols in Encryption Algorithms.
thus, If plaintext is viewed as a sequence of bits, replace plaintext bit patterns with cipher text bit patterns.
- Caesar Cipher
- Monoalphabetic Cipher
- Playfair Cipher
- Hill Cipher
- Polyalphabetic Ciphers
- One-Time Pad
We will now Implement Caesar Cipher and Playfair Cipher Encryption Algorithms.
1. Caesar Cipher
Lets first write the main function , which will print a menu to perform the specified desired function.
Now, we will write the Encryption function, which will encrypt the incoming Plain Text.
The above code takes in a Plain text and a Key value as user input, then loops over it, taking the plain text value, adding the key value to them and substituting it with the new cipher text value formed.
Now let’s write a Decryption function, that decrypts the ciphered text to plain text.
The above code takes in a ciphered text and a key value as a user input, then decrypts it back to plain text by taking a cipher text value, subtracting key from it, and substituting it with the original plain text value formed.
Both the functions call the main function again to reprint the menu and keep the program running, until the user decides to exit from the menu.
2. Playfair Cipher
The above code takes a key value as an input and removes all the duplicate letters from the entered key. Then, a list is generated which contains all alphabets from A-Z. Another list having indexes or numbers for those letters is generated which contains all the letters included in the key to know exactly what elements to add into the 5×5 matrix.
Now using the NumPy library, a 5×5 matrix is formed from the key list. At last , the code accepts user inputs for the plain text to encrypt.
In the above piece of code, the first two for loops check the number of letters and convert them into a pair of two. If no letter is left to be paired, instead a padding letter ‘x’ is added to the pair.
The third loop checks for each pair’s each letter’s index in the created dictionary and forms a dictionary of all the indexes of particular letters in all the pairs.
The above code checks for the cipher text conditions as of how the Playfair Cipher works and creates a ciphered text out of the passed pairs and finally prints them.
written by: Priyansh Gupta
Reviewed By: Sayan Chatterjee
If you are Interested In Machine Learning You Can Check Machine Learning Internship Program
Also Check Other Technical And Non Technical Internship Programs