Using cryptography techniques we can generate keys for a plain text which can not be predicted easily. We use Cryptography to ensure the safe and secure flow of data from one source to another without being accessed by a malicious user.
Language used – Python.
Tkinter – This module is used to make GUIs using python language. To know more about tkinter click here.
Basics of Cryptography – Cryptography is used for Secure Communication.
Encryption – The process of encoding a message or information in such a way that only authorized parties can access it. Decryption – The process of taking encoded or encrypted text or other data and converting it back into text.
one-time pad is a type of encryption which is unbreakable. A one-time pad will generate a key, this key is shared by both the user so it does encryption as well as decryption. The key used is generated randomly and this key is combined with the plain text in order to form the ciphertext. We can use different algorithms for the generation of the ciphertext such as
modular XOR, etc. Since the key generated every time is unique, it is impossible to break.
In this example, we use a modular addition. Every letter of the message has it’s numerical value associated with it. This numerical value is mapped with the corresponding letter of the key and ciphertext is generated by doing modular addition operation. if the value exceeds 26, the result will be the mod of the value with 26. Here ‘GEEKS’ acts as a plain message and ‘DFSTL’ acts as the one-time pad key.
G E E K S message 6 (G) 4 (E) 4 (E) 10 (K) 18 (S) message + 3 (D) 5 (F) 18 (S) 19 (T) 11 (L) key = 9 9 22 29 29 message + key = 9 (J) 9 (J) 22 (W) 3 (D) 3 (D) (message + key) mod 26 J J W D D ? ciphertext
Since we used modular addition for the generation of the ciphertext. In order to get back the original message we have to perform modular subtraction. If the value comes out to be negative we will add 26 to the value, the resultant numerical value will result in the generation of the original message.
J J W D D ciphertext 9 (J) 9 (J) 22 (W) 3 (D) 3 (D) ciphertext - 3 (D) 5 (F) 18 (S) 19 (T) 11 (L) key = 6 4 4 -16 -8 ciphertext – key = 6 (G) 4 (E) 4 (E) 10(K) 18 (S) ciphertext – key (mod 26) G E E K S ? message
Below is the implementation.
Note: The default technique used by the module is not as same in the example given. We can apply different formulas for the generation of the ciphertext, however, the underlying principle remains the same.
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.
- Fernet (symmetric encryption) using Cryptography module in Python
- Python | Simple GUI calculator using Tkinter
- Python | Distance-time GUI calculator using Tkinter
- Python - Compound Interest GUI Calculator using Tkinter
- Python | Create a GUI Marksheet using Tkinter
- Python: Weight Conversion GUI using Tkinter
- Python | ToDo GUI Application using Tkinter
- Python | GUI Calendar using Tkinter
- Create a GUI to convert CSV file into excel file using Python
- Tic Tac Toe GUI In Python using PyGame
- Sentiment Detector GUI using Tkinter - Python
- Python - Morse Code Translator GUI using Tkinter
- Create First GUI Application using Python-Tkinter
- Python - SpongeBob Mocking Text Generator GUI using Tkinter
- Python - Spell Corrector GUI using Tkinter
- Python - UwU text convertor GUI using Tkinter
- GST Rate Finder GUI using Python-Tkinter
- Create GUI for Downloading Youtube Video using Python
- Create Copy-Move GUI using Tkinter in Python
- Python - English (Latin) to Hindi (Devanagiri) text convertor GUI using Tkinter
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.