Message Encryption Decryption using Python

FREE Online Courses: Click, Learn, Succeed, Start Now!

We all know how important it is to secure a message in this world of cyber crimes. We all would like our messages to be secure and free from any breach. In this Python Project, we are going to create a Message Encryption and Decryption Application using Tkinter.

About Message Encryption and Decryption

Message Encryption Decryption is an application that converts a text into its encrypted and decrypted form.

Encryption is a technique of altering a text using a key. This alteration in the text prevents it from being used in a malicious manner. This process of hiding the original context of a text to prevent it from malicious use is known as encryption.

Decryption is the process of decoding an encrypted text into its original form using a key.

In this project, we will be implementing both encryption and decryption.

Project Details

We are going to build this project using the Tkinter Module. The Tkinter Module helps us create an easy GUI in python. In the project, the user has to enter the string and within a click of a button, the user will get the encrypted and decrypted form of the text.

Download Python Message Encryption Decryption Code

Before proceeding with the project, please download the python message encryption decryption project source code from the following link: – Message Encryption Decryption Project Source Code

Project Prerequisites

We need to install the Tkinter module to build this project. You can install the same using the following command-

Pip install tk

Project File Structure

Following are the steps to build the project:

1. Importing the Module

2. Creating the GUI

3. Encryption Function

4. Decryption Function

1. Importing the Module:

from tkinter import *
import tkinter as tk
  • We have imported the Tkinter Module as tk. Tk is an alias for Tkinter Module.

2. Creating the GUI:

window.geometry("700x350")
window.title("PythonGeeks")#give title to the window
Label(window, text="Message Encryption Decryption",bg='dark blue',fg='white', font=('Calibri 15')).pack()# a label
  • geometry() – Is to set the size of the GUI Window.
  • title() – is to set the title of the GUI Window.
  • Label() – Is to create a Label widget that displays text.
Label(window, text="Enter the letter to be encrypted:", font=('Calibri 12')).pack()# a label
Entry(window,textvariable=text).pack()
Label(window, text="Enter the key:", font=('Calibri 12')).pack()# a label
Entry(window,textvariable=key).pack()
 
Button(window,text="ENCRYPT",bg='pink',command=encryption).pack()
Button(window,text="DECRYPT",bg='pink',command=decryption).pack()

1. Entry() – is to create an entry field. We have created two entry fields.

  • For entering the key of encryption and decryption.
  • Entering the text.

2. Button() – is to create a button. We have created two buttons.

  • For encryption.
  • For decryption.

3. Encryption Function:

alphabets="abcdefghijklmnopqrstuvwxyz"
  • We have created a string called alphabets which has all the alphabets.
def encryption():
    t=text.get()
    k=key.get()
    en=""  
 
    for letter in t:
        new_position=(alphabets.find(letter)+k)%len(alphabets)
        en+=alphabets[new_position]
    Label(window,text="Decryption is:",font=('Calibri 12')).pack()
    Label(window,text=de,font=('Calibri 12'),bg='red').pack()
  • get() – is to get the value.
  • find() – to find the letter in the string.
  • len() – to find the length.
  • We find and replace each letter of the text entered and encrypt and decrypt it using the key. And finally display the result using Label().

4. Decryption Function:

def decryption():
    t=text.get()
    k=key.get()
    de=""  
 
    for letter in t:
        new_position=(alphabets.find(letter)-k)%len(alphabets)
        de+=alphabets[new_position]
 
    Label(window,text="Decryption is:",font=('Calibri 12')).pack()
    Label(window,text=de,font=('Calibri 12'),bg='red').pack()
  • Same as encryption function.
window.mainloop()
  • mainloop() – is to display all the widgets on the GUI screen.

Python Message Encryption Decryption Output

This is the output of the Message Encryption Decryption –

python message encryption decryption output

Summary

Hurray! We have successfully completed the Message Encryption Decryption Project using Python. Now you can convert a text into its encrypted and decrypted form very easily. Hope you enjoyed building this project with PythonGeeks.

If you are Happy with PythonGeeks, do not forget to make us happy with your positive feedback on Google | Facebook


Leave a Reply

Your email address will not be published. Required fields are marked *