-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashGenGUI.py
More file actions
130 lines (102 loc) · 4.46 KB
/
HashGenGUI.py
File metadata and controls
130 lines (102 loc) · 4.46 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# ****************************************************************************************
# Title: Hash Generator GUI *******************************************************
# Developed by: Ryan Hatch *******************************************************
# Date: October 12th 2023 *******************************************************
# Last Updated: October 12th 2023 *******************************************************
# Version: C1.5 *******************************************************
# ****************************************************************************************
import hashlib
import os
import pyperclip
from cryptography.fernet import Fernet
import tkinter as tk
from tkinter import simpledialog, messagebox
KEY_FILE = "GUIencryption_keyGUI.key"
# Functions:
def save_key_to_file(key):
with open(KEY_FILE, "wb") as key_file:
key_file.write(key)
def load_key_from_file():
with open(KEY_FILE, "rb") as key_file:
return key_file.read()
if not os.path.exists(KEY_FILE):
key = Fernet.generate_key()
save_key_to_file(key)
else:
key = load_key_from_file()
cipher_suite = Fernet(key)
def clear_clipboard():
pyperclip.copy('')
output_label.config(text="Clipboard cleared.")
def copy_to_clipboard():
text_to_copy = output_label.cget("text").split(": ", 1)[-1] # Split the text and get the part after ": "
if text_to_copy:
pyperclip.copy(text_to_copy)
messagebox.showinfo("Info", "Output copied to clipboard!")
else:
messagebox.showwarning("Warning", "No output to copy!")
def encrypt_text():
text_to_encrypt = text_entry.get()
encrypted_text = cipher_suite.encrypt(text_to_encrypt.encode()).decode()
output_label.config(text=f"Encrypted Text: {encrypted_text}")
def decrypt_text():
encrypted_text = text_entry.get()
decrypted_text = cipher_suite.decrypt(encrypted_text.encode()).decode()
output_label.config(text=f"Decrypted Text: {decrypted_text}")
def generate_hash():
salt = simpledialog.askstring("Input", "Enter salt value:")
sha256_hash = hashlib.sha256((text_entry.get() + salt).encode()).hexdigest()
output_label.config(text=f"Hash: {sha256_hash}")
def verify_hash():
input_hash = simpledialog.askstring("Input", "Enter the hash to verify:")
original_text = simpledialog.askstring("Input", "Enter the original text to verify against the hash:")
salt = simpledialog.askstring("Input", "Enter the salt value used during hashing:")
computed_hash = hashlib.sha256((original_text + salt).encode()).hexdigest()
if computed_hash == input_hash:
output_label.config(text="Hash successfully verified.")
else:
output_label.config(text="Verification unsuccessful. Hash does not match.")
def on_key_press(event):
# Check if the focus is on the text_entry widget
if root.focus_get() == text_entry:
return
if event.keysym == '1':
encrypt_text()
elif event.keysym == '2':
decrypt_text()
elif event.keysym == '3':
generate_hash()
elif event.keysym in ['c', 'C']:
copy_to_clipboard()
elif event.keysym in ['v', 'V']:
verify_hash()
elif event.keysym in ['x', 'X']:
clear_clipboard()
elif event.keysym in ['q', 'Q']:
root.destroy()
# GUI setup:
root = tk.Tk()
root.title("Hash Generator Lite with Encryption")
root.bind('<Key>', on_key_press)
# Widgets:
text_label = tk.Label(root, text="Enter Text:")
text_label.pack(pady=10)
text_entry = tk.Entry(root, width=50)
text_entry.pack(pady=10)
encrypt_button = tk.Button(root, text="1. Encrypt", command=encrypt_text)
encrypt_button.pack(pady=10)
decrypt_button = tk.Button(root, text="2. Decrypt", command=decrypt_text)
decrypt_button.pack(pady=10)
hash_button = tk.Button(root, text="3. Generate Hash", command=generate_hash)
hash_button.pack(pady=10)
verify_button = tk.Button(root, text="V. Verify Hash", command=verify_hash)
verify_button.pack(pady=10)
copy_button = tk.Button(root, text="C. Copy Output", command=copy_to_clipboard)
copy_button.pack(pady=10)
clear_button = tk.Button(root, text="x. Clear Clipboard", command=clear_clipboard)
clear_button.pack(pady=10)
quit_button = tk.Button(root, text="q. Quit", command=root.destroy)
quit_button.pack(pady=10)
output_label = tk.Label(root, text="")
output_label.pack(pady=10)
root.mainloop()