-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHashGenie.py
More file actions
129 lines (104 loc) · 4.99 KB
/
Copy pathHashGenie.py
File metadata and controls
129 lines (104 loc) · 4.99 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
import hashlib
import pyfiglet as fig
from colorama import Fore
import os
def generate_hash(data, hash_type):
if hash_type == 1:
hasher = hashlib.md5()
elif hash_type == 2:
hasher = hashlib.sha1()
elif hash_type == 3:
hasher = hashlib.sha256()
elif hash_type == 4:
hasher = hashlib.sha512()
elif hash_type == 5:
hasher = hashlib.blake2b()
else:
raise ValueError("Invalid hash type")
hasher.update(data.encode('utf-8'))
return hasher.hexdigest()
def hash_file(file_path, hash_type):
try:
with open(file_path, 'rb') as file:
data = file.read()
print(Fore.LIGHTCYAN_EX + "Hashing The file ......")
except FileNotFoundError:
print("File not found.")
return
if hash_type == 1:
hasher = hashlib.md5()
elif hash_type == 2:
hasher = hashlib.sha1()
elif hash_type == 3:
hasher = hashlib.sha256()
elif hash_type == 4:
hasher = hashlib.sha512()
elif hash_type == 5:
hasher = hashlib.blake2b()
else:
raise ValueError("Invalid hash type")
hasher.update(data)
hash_value = hasher.hexdigest()
file_name, file_extension = os.path.splitext(file_path)
hashed_file_path = f"{file_name}_hash{file_extension}"
with open(hashed_file_path, 'w') as hashed_file:
hashed_file.write(hash_value)
return hashed_file_path
def main():
for i in fig.figlet_format(' HashGenie ', font='big', width=200).split('\n\n'):
print(Fore.LIGHTMAGENTA_EX + i.center(120) + Fore.RESET)
print(Fore.LIGHTBLUE_EX + "HashGenie is a Python tool that generates hash values for input data using different hash algorithms. Users can input data and select a hash algorithm (e.g., MD5, SHA-1, SHA-256) to generate the corresponding hash value. HashGenie provides secure and efficient hashing functionalities for data integrity verification and password storage." + Fore.RESET)
print(Fore.CYAN + "Choose an option:")
print("1. Hash a message")
print("2. Hash a file")
option = input("Enter your choice (1/2): ").strip()
if option == '1':
data = input("Enter the message to hash: ")
print(Fore.LIGHTYELLOW_EX + "Choose a hash algorithm:")
print("1. MD5 " + Fore.RED + "(⚠️ Cryptographically broken - for legacy use only)" + Fore.LIGHTYELLOW_EX)
print("2. SHA-1 " + Fore.RED + "(⚠️ Cryptographically broken - for legacy use only)" + Fore.LIGHTYELLOW_EX)
print("3. SHA-256 " + Fore.GREEN + "(✓ Recommended)" + Fore.LIGHTYELLOW_EX)
print("4. SHA-512 " + Fore.GREEN + "(✓ Highly Secure)" + Fore.LIGHTYELLOW_EX)
print("5. BLAKE2b " + Fore.LIGHTGREEN_EX + "(✓ Modern & Fast)" + Fore.LIGHTYELLOW_EX)
hash_type = input("Enter your choice (1/2/3/4/5): "+ Fore.RESET).strip()
if hash_type not in {'1', '2', '3', '4', '5'}:
print(Fore.RED + "Invalid hash algorithm choice." + Fore.RESET)
return
hash_value = generate_hash(data, int(hash_type))
print(Fore.LIGHTGREEN_EX + f"Hash value: {hash_value}" + Fore.RESET)
elif option == '2':
file_path = input("Enter the path to the file: ")
if not os.path.exists(file_path):
print(Fore.RED + f"Error: File '{file_path}' not found." + Fore.RESET)
return
print(Fore.LIGHTYELLOW_EX + "Choose a hash algorithm:")
print("1. MD5 " + Fore.RED + "(⚠️ Cryptographically broken - for legacy use only)" + Fore.LIGHTYELLOW_EX)
print("2. SHA-1 " + Fore.RED + "(⚠️ Cryptographically broken - for legacy use only)" + Fore.LIGHTYELLOW_EX)
print("3. SHA-256 " + Fore.GREEN + "(✓ Recommended)" + Fore.LIGHTYELLOW_EX)
print("4. SHA-512 " + Fore.GREEN + "(✓ Highly Secure)" + Fore.LIGHTYELLOW_EX)
print("5. BLAKE2b " + Fore.LIGHTGREEN_EX + "(✓ Modern & Fast)" + Fore.LIGHTYELLOW_EX)
hash_type = input("Enter your choice (1/2/3/4/5): "+ Fore.RESET).strip()
if hash_type not in {'1', '2', '3', '4', '5'}:
print(Fore.RED + "Invalid hash algorithm choice." + Fore.RESET)
return
hashed_file_path = hash_file(file_path, int(hash_type))
if hashed_file_path:
print(Fore.LIGHTCYAN_EX + f"Hashed file saved successfully: {hashed_file_path}" + Fore.RESET )
else:
print("Invalid option.")
return
while True:
choice = input(Fore.LIGHTBLUE_EX + "\nDo you want to rerun this tool? (Y/N): " + Fore.RESET).lower()
if choice in {'y', 'n'}:
if choice == 'n':
print("Returning to main page...")
os.system('cls' if os.name == 'nt' else 'clear')
os.system('python main.py')
return
else:
os.system('cls' if os.name == 'nt' else 'clear')
main()
else:
print(Fore.RED + "Invalid choice. Please enter 'y' or 'n'." + Fore.RESET)
if __name__ == "__main__":
main()