Demo_3
Demo_3
# (Các hàm liên quan đến mã hóa và giải mã ElGamal được giữ nguyên)
def encrypt_action():
if not public_key:
messagebox.showerror("Error", "Please generate keys first!")
return
file_path = filedialog.askopenfilename(title="Select File to Encrypt")
if not file_path:
return
try:
encrypted_file = encrypt_file(file_path, public_key)
messagebox.showinfo("Encryption", f"File encrypted successfully:
{encrypted_file}")
except Exception as e:
messagebox.showerror("Error", f"Encryption failed: {e}")
def decrypt_action():
if not private_key:
messagebox.showerror("Error", "Please generate keys first!")
return
file_path = filedialog.askopenfilename(title="Select File to Decrypt")
if not file_path:
return
try:
decrypted_file = decrypt_file(file_path, private_key)
messagebox.showinfo("Decryption", f"File decrypted successfully:
{decrypted_file}")
except Exception as e:
messagebox.showerror("Error", f"Decryption failed: {e}")
# Khung bao
frame = ttk.Frame(root, padding="20")
frame.pack(fill=tk.BOTH, expand=True)
# Tiêu đề
title_label = ttk.Label(frame, text="ElGamal File Encryption", font=("Arial",
18, "bold"))
title_label.pack(pady=10)