Message Encryption & Decryption Program

Hello coders we create this project with Python Tkinter and base64 Module

  •   In this project we create message encryption&decryption program

Libraries used-

  >>Tkinter(for GUI)

>>Pillow(for Backgroung Image)

  >>base64 (for message encryption and decryption)

Step to create GUI-

  • Install Tkinter using pip install
  • Install Pillow using pip install
  • Install base64 using pip install
  • Import Tkinter
  • Create the main window
  • Import backgroung png
  • Create entry and buttons

Algorithm-

  • Create function of encryption using base64-encode.
  • Create window for encryption output
  • Create function of decryption using base64-decode.
  • Create window for decryption output.
  • Create function for reset
  • Create entry for text and password
  • create buttons of encrypt, decrypt and reset and add command
#importing Libraries---------------------------------------------------------------------------------------------------

from tkinter import *

from tkinter import messagebox

from PIL import ImageTk, Image

from tkinter import ttk

import base64

import os



screen=Tk()



#Encryption Function---------------------------------------------------------------------------------------------------

def enc():

    if (E2.get()=="1234"):

        G1=Tk()

        G1.title("Encrypted Message")

        G1.geometry("400x200")

        G1.configure(bg="#5BB55E")

        mydata=E1.get(1.0,END)

        em=mydata.encode("ascii")

        b64_b=base64.b64encode(em)

        encrypt=b64_b.decode("ascii")



        

        Label(G1,text="Encrypted Message",font=("arial",20,"bold"),fg="white",bg="#5BB55E").place(x=75,y=0)

        E3=Text(G1,font="Robote 10",bg="white",relief=GROOVE,wrap=WORD,bd=0)

        E3.place(x=10,y=40,width=380,height=150)

        E3.insert(END,encrypt)



        

        

        

        

    elif E2.get()=="":

        messagebox.showerror("Encryption","Can't Enpty....")

    else:

        messagebox.showerror("Encryption","Invalid Password")

    G1.mainloop()



    

#Decryption Function--------------------------------------------------------------------------------------------------

def dec():

    if (E2.get()=="1234"):

        G2=Tk()

        G2.title("Decrypted Message")

        G2.geometry("400x200")

        G2.configure(bg="#E9393F")

        mydata=E1.get(1.0,END)

        dm=mydata.encode("ascii")

        b64_b=base64.b64decode(dm)

        decrypt=b64_b.decode("ascii")





        

        Label(G2,text="Decrypted Message",font=("arial",20,"bold"),fg="white",bg="#E9393F").place(x=75,y=0)

        E4=Text(G2,font="Robote 10",bg="white",relief=GROOVE,wrap=WORD,bd=0)

        E4.place(x=10,y=40,width=380,height=150)

        E4.insert(END,decrypt)

        

    elif E2.get()=="":

        messagebox.showerror("Encryption","Can't Enpty....")

    else:

        messagebox.showerror("Encryption","Invalid Password")

    G2.mainloop()

    

#Reset Function-------------------------------------------------------------------------------------------------------

def reset():

    E2.delete(0,END)

    E1.delete(1.0,END)





#For putting Icon-----------------------------------------------------------------------------------------------------

image_icon=PhotoImage(file="logo.png")

screen.iconphoto(False,image_icon)





#For putting title----------------------------------------------------------------------------------------------------

screen.title("Message Tool")





#For putting Image as background--------------------------------------------------------------------------------------

screen.geometry("800x500+0+0")

img = ImageTk.PhotoImage(Image.open("msg.png"))

panel = Label(screen, image = img)

panel.place(x=0,y=0)



#Encryption & Decryption box------------------------------------------------------------------------------------------ 

L1=Label(screen,text="Enter Text For Encryption & Decryption ",

         font=("Cambria",20,"bold"),fg="white",bg="#25252E")

L1.place(x=30,y=15)



#Encryption & Decryption entry box------------------------------------------------------------------------------------

E1=Text(screen,font=("Cambria",15,"bold"),fg="#151D31",relief=GROOVE,wrap=WORD,bd=0)

E1.place(x=28,y=60,width=500,height=180)



#Enter key box--------------------------------------------------------------------------------------------------------  

L2=Label(screen,text="Enter The Secret Key",

         font=("Cambria",20,"bold"),fg="white",bg="#25252E")

L2.place(x=140,y=250)



#key entry box--------------------------------------------------------------------------------------------------------

E2=Entry(screen,font=("Cambria",15,"bold"),show="*",fg="#151D31",relief=GROOVE,bd=0,width=15)

E2.place(x=180,y=300)



#Encryption button----------------------------------------------------------------------------------------------------

B1=Button(screen,text="ENCRYPT",font=("Cambria",15,"bold"),fg="white",bg="#5BB55E",width=15,command=enc)

B1.place(x=50,y=350)



#Decryption button----------------------------------------------------------------------------------------------------

B2=Button(screen,text="DECRYPT",font=("Cambria",15,"bold"),fg="white",bg="#E9393F",width=15,command=dec)

B2.place(x=320,y=350)



#Rest button----------------------------------------------------------------------------------------------------------

B3=Button(screen,text="Reset",font=("Cambria",18,"bold"),fg="white",bg="#ED941C",width=30,command=reset)

B3.place(x=70,y=410)



screen.mainloop()


Output:

Write a comment