Educational File Encryptor GUI (Python AES Project) | FuzzuTech
Demo :
Click Video πππ
Features :
-
Python AES encryption GUI app
-
File encryption & decryption demo
-
Educational safe sandbox project
-
Tkinter + PyCryptodome example
-
Python cybersecurity learning tool
Code :
# Important package install : pip install pycryptodome
import os
import tkinter as tk
from tkinter import filedialog, messagebox
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
from Crypto import Random
# ---------- Encryption ---------- #
def encrypt(key, filename):
try:
chunksize = 64 * 1024
outputFile = filename + ".locked"
filesize = str(os.path.getsize(filename)).zfill(16)
IV = Random.new().read(16)
encryptor = AES.new(key, AES.MODE_CBC, IV)
with open(filename, 'rb') as infile:
with open(outputFile, 'wb') as outfile:
outfile.write(filesize.encode('utf-8'))
outfile.write(IV)
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += b' ' * (16 - len(chunk) % 16)
outfile.write(encryptor.encrypt(chunk))
messagebox.showinfo("✅ Encrypted", f"File Encrypted Successfully!\nSaved as: {outputFile}")
except Exception as e:
messagebox.showerror("❌ Error", f"Encryption Failed!\n{e}")
# ---------- Decryption ---------- #
def decrypt(key, filename):
try:
chunksize = 64 * 1024
outputFile = filename.replace(".locked", "")
with open(filename, 'rb') as infile:
filesize = int(infile.read(16))
IV = infile.read(16)
decryptor = AES.new(key, AES.MODE_CBC, IV)
with open(outputFile, 'wb') as outfile:
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
outfile.write(decryptor.decrypt(chunk))
outfile.truncate(filesize)
messagebox.showinfo("✅ Decrypted", f"File Decrypted Successfully!\nSaved as: {outputFile}")
except Exception as e:
messagebox.showerror("❌ Error", f"Decryption Failed!\n{e}")
# ---------- Helpers ---------- #
def getKey(password):
hasher = SHA256.new(password.encode('utf-8'))
return hasher.digest()
def encryptFile():
filename = filedialog.askopenfilename(title="Select File to Encrypt")
if not filename:
return
password = passwordEntry.get()
if not password:
messagebox.showwarning("⚠️ Warning", "Enter password before encrypting!")
return
encrypt(getKey(password), filename)
def decryptFile():
filename = filedialog.askopenfilename(title="Select File to Decrypt (.locked)")
if not filename:
return
password = passwordEntry.get()
if not password:
messagebox.showwarning("⚠️ Warning", "Enter password before decrypting!")
return
decrypt(getKey(password), filename)
def togglePassword():
if passwordEntry.cget("show") == "*":
passwordEntry.config(show="")
toggleBtn.config(text="π Hide")
else:
passwordEntry.config(show="*")
toggleBtn.config(text="π️ Show")
# ---------- GUI ---------- #
root = tk.Tk()
root.title("⚡ Educational Ransomware Simulator (Safe)")
root.geometry("500x400")
root.config(bg="#111827")
root.resizable(False, False)
tk.Label(root, text="⚡ Educational Ransomware Simulator", fg="#00FFB0", bg="#111827",
font=("Helvetica", 18, "bold")).pack(pady=15)
tk.Label(root, text="π 100% Safe for Learning — Encrypt & Decrypt Instantly", fg="#A3A3A3",
bg="#111827", font=("Helvetica", 10)).pack(pady=5)
frame = tk.Frame(root, bg="#111827")
frame.pack(pady=20)
tk.Label(frame, text="Enter Secret Key:", fg="white", bg="#111827", font=("Helvetica", 11)).grid(row=0, column=0, padx=5)
passwordEntry = tk.Entry(frame, width=30, show="*", font=("Helvetica", 11))
passwordEntry.grid(row=0, column=1, padx=5)
toggleBtn = tk.Button(frame, text="π️ Show", command=togglePassword, bg="#222", fg="#00FFB0", font=("Helvetica", 9))
toggleBtn.grid(row=0, column=2, padx=5)
tk.Button(root, text="Encrypt File π", width=20, command=encryptFile, bg="#00B050", fg="white",
font=("Helvetica", 12, "bold")).pack(pady=10)
tk.Button(root, text="Decrypt File π", width=20, command=decryptFile, bg="#0078D7", fg="white",
font=("Helvetica", 12, "bold")).pack(pady=5)
tk.Label(root, text="⚠️ Educational Use Only – Don’t Use on Others' Data", fg="#FF5050", bg="#111827",
font=("Helvetica", 9, "italic")).pack(pady=30)
root.mainloop()
Comments
Post a Comment