Hiding some data is known as encryption. When plain text is encrypted it becomes unreadable and is known as ciphertext. In a Substitution cipher, any character of plain text from the given fixed set of characters is substituted by some other character from the same set depending on a key. For example with a shift of 1, A would be replaced by B, B would become C, and so on.
Note: Special case of Substitution cipher is known as Caesar cipher where the key is taken as 3.
The encryption can be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,…, Z = 25. Encryption of a letter by a shift n can be described mathematically as.
(Encryption Phase with shift n)
(Decryption Phase with shift n)
Plain Text: I am studying Data Encryption Key: 4 Output: M eq wxyhCmrk Hexe IrgvCtxmsr Plain Text: ABCDEFGHIJKLMNOPQRSTUVWXYZ Key: 4 Output: EFGHIJKLMNOPQRSTUVWXYZabcd
Algorithm for Substitution Cipher:
- A String of both lower and upper case letters, called PlainText.
- An Integer denoting the required key.
- Create a list of all the characters.
- Create a dictionary to store the subtitution for all characters.
- For each character, transform the given character as per the rule, depending on whether we’re encrypting or decrypting the text.
- Print the new string generated.
Below is the implementation.
Cipher Text is: M eq wxyhCmrk Hexe IrgvCtxmsr Recovered plain text : I am studying Data Encryption
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Difference between Monoalphabetic Cipher and Polyalphabetic Cipher
- Caesar Cipher in Cryptography
- Vigenère Cipher
- XOR Cipher
- Rail Fence Cipher - Encryption and Decryption
- Implementation of Affine Cipher
- Columnar Transposition Cipher
- ROT13 cipher
- Implementing Atbash Cipher
- Baconian Cipher
- Keyword Cipher
- Null Cipher
- Hill Cipher
- Transforming a Plain Text message to Cipher Text
- Playfair Cipher with Examples
- Bifid Cipher in Cryptography
- Feistel Cipher
- Autokey Cipher | Symmetric Ciphers
- Encrypt using XOR Cipher with Repeating Key
- Latin alphabet cipher
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.