-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (57 loc) · 2.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import tkinter as tk
from tkinter import ttk
from cryptography.fernet import Fernet
# Generate a random AES key
def generate_aes_key():
return Fernet.generate_key()
# Initialize the cipher suite with a given key
def initialize_cipher_suite(key):
return Fernet(key)
# Encrypt text using AES-CBC
def encrypt_text(text, cipher_suite):
encrypted_text = cipher_suite.encrypt(text.encode())
return encrypted_text
# Function to perform encryption and update the result container
def perform_encryption():
input_text = entry.get()
aes_key = generate_aes_key()
cipher_suite = initialize_cipher_suite(aes_key)
encrypted_text = encrypt_text(input_text, cipher_suite)
# Insert the encrypted text and AES key into the Text widget
output_text.config(state=tk.NORMAL) # Enable editing
output_text.delete(1.0, tk.END) # Clear existing content
output_text.insert(tk.END, f"Encrypted Text: {encrypted_text.decode()}\nAES Key: {aes_key.decode()}")
output_text.config(state=tk.DISABLED) # Disable editing
# Create the main window
window = tk.Tk()
window.title("Text Encryption")
# Set window size and make it unresizable
window.geometry("350x400") # Fixed window size
window.resizable(False, False) # Disable resizing
# Create a themed style
style = ttk.Style()
# Configure the style for the input field
style.configure("TEntry",
font=("Arial", 24), # Increase font size
padding=15, # Add padding
width=40) # Decrease width for a longer input field
# Create an input frame to hold the input field and button
input_frame = ttk.Frame(window)
input_frame.pack(fill="both", expand=True, padx=20, pady=20)
# Create an input field with a watermark for encryption
entry = ttk.Entry(input_frame, justify="center", style="TEntry")
entry.insert(0, "Enter the text")
entry.bind("<FocusIn>", lambda event: entry.delete(0, "end")) # Clear the watermark on focus
entry.pack(side="left", padx=5, pady=10) # Increase padding
# Create a themed button to trigger encryption
encrypt_button = ttk.Button(input_frame, text="Encrypt", command=perform_encryption, style="TButton")
encrypt_button.pack(side="left", padx=10, pady=10) # Increase padding for a slightly larger button
# Create a Text widget to display the output
output_text = tk.Text(window, wrap=tk.WORD, font=("Arial", 14), height=8) # Increase font size and set height
output_text.pack(fill="both", expand=True, padx=20, pady=20)
output_text.config(state=tk.DISABLED) # Make the Text widget read-only
# Create a label for the watermark
watermark_label = ttk.Label(window, text="Created by Denis Dimov", font=("Arial", 10), foreground="gray")
watermark_label.place(x=10, y=10) # Adjust the position of the watermark label
# Start the GUI main loop
window.mainloop()