from tkinter import *
from tkinter import messagebox
import base64
def decrypt():
try:
password = code.get()
if password == "1234":
encrypted_message = Text1.get(1.0, END).strip()
if not encrypted_message:
messagebox.showinfo("Info", "Please enter an encrypted message to decrypt.")
return
base64_bytes = encrypted_message.encode('ascii')
decoded_bytes = base64.b64decode(base64_bytes)
decrypted_message = decoded_bytes.decode('ascii')
# You can do something with the decrypted_message, for example, display it or save it.
print("Decrypted Message:", decrypted_message)
# Optionally, you can show a message box indicating success.
messagebox.showinfo("Decryption", "Message decrypted successfully.")
else:
messagebox.showinfo("Invalid Password", "Invalid password. Access denied.")
except Exception as e:
messagebox.showerror("Error", f"An error occurred during decryption: {e}")
def encrypt():
try:
password = code.get()
if password == "1234":
message = Text1.get(1.0, END).strip()
if not message:
messagebox.showinfo("Info", "Please enter a message to encrypt.")
return
encode_message = message.encode('ascii')
base64_bytes = base64.b64encode(encode_message)
encrypted_message = base64_bytes.decode('ascii')
# You can do something with the encrypted_message, for example, display it or save it.
print("Encrypted Message:", encrypted_message)
# Optionally, you can show a message box indicating success.
messagebox.showinfo("Encryption", "Message encrypted successfully.")
else:
messagebox.showinfo("Invalid Password", "Invalid password. Access denied.")
except Exception as e:
messagebox.showerror("Error", f"An error occurred during encryption: {e}")
def reset():
code.set("")
Text1.delete(1.0, END)
def main_screen():
try:
global screen
global code
global Text1
screen = Tk()
screen.geometry("375x398")
# Icon
Image_icon = PhotoImage(file="img-adeaPutqPUnzaEN_1673037963.webp")
screen.iconphoto(False, Image_icon)
# Create a label with a title
label_title = Label(screen, text="Enter Text for Encryption and Decryption", fg="black", font=("calibri", 13))
label_title.place(x=10, y=10)
Text1 = Text(screen, font=("Roboto", 20), bg="white", relief=GROOVE, wrap=WORD, bd=0)
Text1.place(x=10, y=50, width=355, height=100)
Label(text="Enter Secret key for Encryption and Decryption", fg="black", font=("calibri", 13)).place(x=10, y=170)
code = StringVar()
Entry(textvariable=code, width=19, bd=0, font=("arial", 25), show="*").place(x=10, y=200)
# Buttons
Button(text="Encrypt", height=2, width=23, bg="#FF004D", fg="white", bd=0, command=encrypt).place(x=10, y=250)
Button(text="Decrypt", height=2, width=23, bg="#00bd56", fg="white", bd=0, command=decrypt).place(x=200, y=250)
Button(text="Reset", height=2, width=50, bg="#3559E0", fg="white", bd=0, command=reset).place(x=10, y=300)
screen.title("Encryption and decryption tool")
screen.mainloop()
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {e}")
from tkinter import * from tkinter import messagebox import base64
def decrypt(): try: password = code.get()
def encrypt(): try: password = code.get()
def reset(): code.set("") Text1.delete(1.0, END)
def main_screen(): try: global screen global code global Text1
if name == "main": main_screen()