Encrypt Any PDF or File Instantly – Fuzzu Encryptor GUI | Python + Fernet + customtkinter
Demo :
Click Video πππ
Features:
-
1 Hero image of the app GUI in dark mode
-
Embedded YouTube Short
-
Full description of features and how-to
-
Download button (optional zip for demo if hosting available)
-
Social share buttons
-
CTA: Follow FuzzuTech on YouTube, Instagram & Facebook
Code :
from cryptography.fernet import Fernet
import customtkinter as ctk
from tkinter import filedialog, messagebox
import os
# --- Encryption Function ---
def encrypt_file(file_path):
if file_path.endswith(".enc") or file_path.endswith(".key"):
raise Exception("Please select a fresh file (not an encrypted or key file).")
key = Fernet.generate_key()
fernet = Fernet(key)
with open(file_path, "rb") as original_file:
original_data = original_file.read()
encrypted_data = fernet.encrypt(original_data)
encrypted_path = file_path + ".enc"
with open(encrypted_path, "wb") as encrypted_file:
encrypted_file.write(encrypted_data)
key_path = encrypted_path + ".key"
with open(key_path, "wb") as key_file:
key_file.write(key)
return encrypted_path, key_path
# --- Decryption Function ---
def decrypt_file(file_path):
key_path = file_path + ".key"
if not os.path.exists(key_path):
raise FileNotFoundError(f"Key file not found!\nExpected: {key_path}")
with open(key_path, "rb") as key_file:
key = key_file.read()
fernet = Fernet(key)
with open(file_path, "rb") as encrypted_file:
encrypted_data = encrypted_file.read()
try:
decrypted_data = fernet.decrypt(encrypted_data)
except Exception as e:
raise Exception(f"Decryption failed:\n{str(e)}\nEnsure correct file/key combination.")
# Restore original file name
if file_path.endswith(".pdf.enc"):
output_path = file_path.replace(".pdf.enc", "_decrypted.pdf")
elif file_path.endswith(".enc"):
output_path = file_path.replace(".enc", "_decrypted")
else:
output_path = file_path + "_decrypted"
with open(output_path, "wb") as output_file:
output_file.write(decrypted_data)
return output_path
# --- GUI Setup ---
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
app = ctk.CTk()
app.geometry("500x350")
app.title("π Fuzzu Encryptor GUI")
file_path = ctk.StringVar()
# --- GUI Functions ---
def select_file():
file_path.set(filedialog.askopenfilename())
def handle_encrypt():
if not file_path.get():
messagebox.showwarning("Warning", "Please select a file!")
return
try:
enc_path, key_path = encrypt_file(file_path.get())
messagebox.showinfo("Success", f"Encrypted Successfully!\nSaved As:\n{enc_path}\nKey File:\n{key_path}")
except Exception as e:
messagebox.showerror("Error", f"Encryption Failed:\n{str(e)}")
def handle_decrypt():
if not file_path.get():
messagebox.showwarning("Warning", "Please select an encrypted (.enc) file!")
return
try:
output_path = decrypt_file(file_path.get())
messagebox.showinfo("Success", f"Decryption Successful!\nSaved As:\n{output_path}")
except Exception as e:
messagebox.showerror("Error", f"Decryption Failed:\n{str(e)}")
# --- GUI Layout ---
ctk.CTkLabel(app, text="Select File to Encrypt/Decrypt:", font=("Arial", 16)).pack(pady=15)
ctk.CTkEntry(app, textvariable=file_path, width=380).pack(pady=5)
ctk.CTkButton(app, text="π Browse", command=select_file, fg_color="#3B82F6").pack(pady=5)
ctk.CTkButton(app, text="π Encrypt File", command=handle_encrypt, fg_color="#EF4444").pack(pady=10)
ctk.CTkButton(app, text="π Decrypt File", command=handle_decrypt, fg_color="#10B981").pack(pady=5)
app.mainloop()
Comments
Post a Comment