Zenith Weaver Python GUI

👤 Sharing: AI
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import os
import hashlib

class ZenithWeaverApp:
    def __init__(self, master):
        self.master = master
        master.title("Zenith Weaver")
        master.geometry("800x600")

        # Notebook for tabbed interface
        self.notebook = ttk.Notebook(master)
        self.notebook.pack(expand=True, fill='both', padx=10, pady=10)

        # Tab 1: File Integrity Checker
        self.file_integrity_tab = ttk.Frame(self.notebook)
        self.notebook.add(self.file_integrity_tab, text='File Integrity')
        self.create_file_integrity_tab(self.file_integrity_tab)

        # Tab 2: Secure Note Pad
        self.secure_notepad_tab = ttk.Frame(self.notebook)
        self.notebook.add(self.secure_notepad_tab, text='Secure Note Pad')
        self.create_secure_notepad_tab(self.secure_notepad_tab)

        # Tab 3: Simple Encryption Tool
        self.encryption_tab = ttk.Frame(self.notebook)
        self.notebook.add(self.encryption_tab, text='Simple Encryption')
        self.create_encryption_tab(self.encryption_tab)

        # Details Button
        self.details_button = tk.Button(master, text='Details', command=self.show_details)
        self.details_button.pack(pady=5)

    def create_file_integrity_tab(self, tab):
        # File Selection Frame
        file_frame = ttk.Frame(tab)
        file_frame.pack(pady=10)

        self.file_path = tk.StringVar()
        file_label = ttk.Label(file_frame, text='Select File:')
        file_label.grid(row=0, column=0, padx=5)

        file_entry = ttk.Entry(file_frame, textvariable=self.file_path, width=50)
        file_entry.grid(row=0, column=1, padx=5)

        browse_button = ttk.Button(file_frame, text='Browse', command=self.browse_file)
        browse_button.grid(row=0, column=2, padx=5)

        # Checksum Calculation Frame
        checksum_frame = ttk.Frame(tab)
        checksum_frame.pack(pady=10)

        self.algorithm = tk.StringVar(value='md5')
        algorithm_label = ttk.Label(checksum_frame, text='Algorithm:')
        algorithm_label.grid(row=0, column=0, padx=5)

        algorithm_menu = ttk.Combobox(checksum_frame, textvariable=self.algorithm, values=['md5', 'sha1', 'sha256'])
        algorithm_menu.grid(row=0, column=1, padx=5)

        calculate_button = ttk.Button(checksum_frame, text='Calculate Checksum', command=self.calculate_checksum)
        calculate_button.grid(row=0, column=2, padx=5)

        # Result Display
        self.checksum_result = tk.StringVar()
        result_label = ttk.Label(tab, text='Checksum:')
        result_label.pack(pady=5)

        result_entry = ttk.Entry(tab, textvariable=self.checksum_result, width=70, state='readonly')
        result_entry.pack(pady=5)

    def create_secure_notepad_tab(self, tab):
        # Text Area
        self.notepad_text = tk.Text(tab, wrap=tk.WORD, width=80, height=20)
        self.notepad_text.pack(padx=10, pady=10)

        # Save/Load Frame
        file_frame = ttk.Frame(tab)
        file_frame.pack(pady=5)

        save_button = ttk.Button(file_frame, text='Save Secure Note', command=self.save_secure_note)
        save_button.grid(row=0, column=0, padx=5)

        load_button = ttk.Button(file_frame, text='Load Secure Note', command=self.load_secure_note)
        load_button.grid(row=0, column=1, padx=5)

    def create_encryption_tab(self, tab):
        # Input Frame
        input_frame = ttk.Frame(tab)
        input_frame.pack(pady=10)

        self.input_text = tk.StringVar()
        input_label = ttk.Label(input_frame, text='Enter Text:')
        input_label.grid(row=0, column=0, padx=5)

        input_entry = ttk.Entry(input_frame, textvariable=self.input_text, width=50)
        input_entry.grid(row=0, column=1, padx=5)

        # Key Frame
        key_frame = ttk.Frame(tab)
        key_frame.pack(pady=5)

        self.encryption_key = tk.StringVar()
        key_label = ttk.Label(key_frame, text='Enter Key:')
        key_label.grid(row=0, column=0, padx=5)

        key_entry = ttk.Entry(key_frame, textvariable=self.encryption_key, width=20, show='*')  # Show '*' for password
        key_entry.grid(row=0, column=1, padx=5)

        # Encryption/Decryption Buttons
        button_frame = ttk.Frame(tab)
        button_frame.pack(pady=5)

        encrypt_button = ttk.Button(button_frame, text='Encrypt', command=self.encrypt_text)
        encrypt_button.grid(row=0, column=0, padx=5)

        decrypt_button = ttk.Button(button_frame, text='Decrypt', command=self.decrypt_text)
        decrypt_button.grid(row=0, column=1, padx=5)

        # Output
        self.output_text = tk.StringVar()
        output_label = ttk.Label(tab, text='Output:')
        output_label.pack(pady=5)

        output_entry = ttk.Entry(tab, textvariable=self.output_text, width=70, state='readonly')
        output_entry.pack(pady=5)

    def browse_file(self):
        filename = filedialog.askopenfilename()
        self.file_path.set(filename)

    def calculate_checksum(self):
        file_path = self.file_path.get()
        if not file_path:
            messagebox.showerror("Error", "Please select a file.")
            return

        algorithm = self.algorithm.get()
        try:
            with open(file_path, 'rb') as f:
                file_content = f.read()
                if algorithm == 'md5':
                    checksum = hashlib.md5(file_content).hexdigest()
                elif algorithm == 'sha1':
                    checksum = hashlib.sha1(file_content).hexdigest()
                elif algorithm == 'sha256':
                    checksum = hashlib.sha256(file_content).hexdigest()
                self.checksum_result.set(checksum)
        except Exception as e:
            messagebox.showerror("Error", str(e))

    def save_secure_note(self):
        note_content = self.notepad_text.get("1.0", tk.END)
        filename = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files", "*.txt"), ("All files", "*")])
        if filename:
            try:
                with open(filename, 'w') as f:
                    f.write(note_content)
                messagebox.showinfo("Success", "Note saved successfully.")
            except Exception as e:
                messagebox.showerror("Error", str(e))

    def load_secure_note(self):
        filename = filedialog.askopenfilename(defaultextension=".txt", filetypes=[("Text files", "*.txt"), ("All files", "*")])
        if filename:
            try:
                with open(filename, 'r') as f:
                    note_content = f.read()
                    self.notepad_text.delete("1.0", tk.END)
                    self.notepad_text.insert(tk.END, note_content)
            except Exception as e:
                messagebox.showerror("Error", str(e))

    def encrypt_text(self):
        text = self.input_text.get()
        key = self.encryption_key.get()
        if not key:
            messagebox.showerror("Error", "Please enter an encryption key.")
            return
        encrypted_text = self.xor_encrypt(text, key)
        self.output_text.set(encrypted_text)

    def decrypt_text(self):
        text = self.output_text.get()
        key = self.encryption_key.get()
        if not key:
            messagebox.showerror("Error", "Please enter the encryption key.")
            return
        decrypted_text = self.xor_encrypt(text, key)
        self.output_text.set(decrypted_text)

    def xor_encrypt(self, text, key):
        encrypted_chars = [chr(ord(c) ^ ord(key[i % len(key)])) for i, c in enumerate(text)]
        return ''.join(encrypted_chars)

    def show_details(self):
        details_message = """
        Zenith Weaver: A multi-functional tool designed to provide several useful features:

        1.  File Integrity Checker:
            -   Allows users to calculate and verify the checksum of a file using MD5, SHA1, or SHA256 algorithms.
            -   Ensures that files have not been tampered with by comparing the calculated checksum with a known value.

        2.  Secure Note Pad:
            -   Provides a simple notepad interface for creating and saving text notes.
            -   Saves notes as standard .txt files.

        3.  Simple Encryption Tool:
            -   Encrypts and decrypts text using a basic XOR encryption algorithm.
            -   Requires a user-provided key for encryption and decryption.

        This tool is designed to be easy to use while providing important security and utility features.
        """
        messagebox.showinfo("Zenith Weaver Details", details_message)


if __name__ == "__main__":
    root = tk.Tk()
    app = ZenithWeaverApp(root)
    root.mainloop()
👁️ Viewed: 13

Comments