-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzencryptCLI.py
More file actions
212 lines (188 loc) · 9.23 KB
/
Copy pathzencryptCLI.py
File metadata and controls
212 lines (188 loc) · 9.23 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# ****************************************************************************************
# Title: Hash Generator CLI *******************************************************
# Developed by: Ryan Hatch *******************************************************
# Date: August 10th 2023 *******************************************************
# Last Updated: October 13th 2023 *******************************************************
# Version: B1.5 *******************************************************
# ****************************************************************************************
import hashlib
import getpass
import os
import pyperclip # For cross-platform clipboard operations
from cryptography.fernet import Fernet
KEY_FILE = "CLIencryption_keyCLI.key"
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()
# Check if the key file exists. If not, generate a new key and save it.
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('') # Clearing the clipboard
print("\n\nClipboard cleared.")
def copy_to_clipboard(text):
pyperclip.copy(text)
print("\n\nOutput copied to clipboard.")
def decrypt_text():
try:
encrypted_text = input("\nEnter the encrypted text to decrypt: ")
decrypted_text = cipher_suite.decrypt(encrypted_text.encode()).decode()
print(f"\nDecrypted Text: {decrypted_text}")
except Exception as e:
print(f"\nError during decryption: {e}")
def encrypt_text():
try:
text_to_encrypt = input("\nEnter the text to encrypt: ")
encrypted_text = cipher_suite.encrypt(text_to_encrypt.encode()).decode()
print(f"\nEncrypted Text: {encrypted_text}")
return encrypted_text
except Exception as e:
print(f"\nError during encryption: {e}")
return None
def encryption_manager():
while True:
print("********************************************************************************")
print("************************| ENCRYPTION MAIN MENU |******************************")
print("********************************************************************************\n\n")
print("********************************************************************************")
print("* 1 | Clear Clipboard |*******************************************************")
# print("* 2 | Copy Output |*******************************************************")
print("********************************************************************************")
print("* 2 | Encrypt |*******************************************************")
print("* 3 | Decrypt |*******************************************************")
print("********************************************************************************")
print("=><=" * 20)
print("=><=" * 20)
print("********************************************************************************")
print("* 4 | ******************| HashGenerator Manager |*****************************")
print("********************************************************************************")
print("\n\n")
choice = input("Enter Option: ")
if choice == "1":
clear_clipboard()
# elif choice == "2":
# # Here, we don't have a specific output to copy, so we might want to inform the user.
# print("\nNo specific output to copy. Use after encryption or decryption.")
elif choice == "2":
encrypted_text = encrypt_text()
if encrypted_text:
copy_to_clipboard(encrypted_text)
elif choice == "3":
decrypt_text()
elif choice == "4":
break
else:
print("\nInvalid Input.")
def print_menu(sha256_hash):
print("\n\n\n")
print("********************************************************************************")
print("************************| HASHGEN MAIN MENU |*********************************")
print("********************************************************************************\n\n")
print("********************************************************************************")
print("* 1 | Clear Clipboard |*******************************************************")
print("* 2 | Copy Output |*******************************************************")
print("********************************************************************************")
print("* 3 | Generate New Hash |*******************************************************")
print("* 4 | Verify Hash |*******************************************************")
print("********************************************************************************")
print("=><=" * 20)
print("=><=" * 20)
print("********************************************************************************")
print("* 5 | ******************| Encryption Manager |********************************")
# print("* 5 | Encryption Manager|*******************************************************")
print("* 6 | Exit |*******************************************************")
print("********************************************************************************")
answer = input("\n\nEnter Option: ")
if answer == "1":
clear_clipboard()
elif answer == "2":
copy_to_clipboard(sha256_hash)
elif answer == "3":
main_loop() # Restart the main loop
elif answer == "4":
verify_hash() # Call the verify_hash function
elif answer == "5":
encryption_manager()
elif answer == "6":
exit() # Exit program
else:
print("\nInvalid Input.")
# def print_menu(sha256_hash):
# print("\n\n\n")
# print("********************************************************************************")
# print("* 1 | Clear Clipboard |*******************************************************")
# print("* 2 | Copy Output |*******************************************************")
# print("* 3 | Generate New Hash |*******************************************************")
# print("* 4 | Verify Hash |*******************************************************")
# print("* 5 | Encrypt |*******************************************************")
# print("* 6 | Decrypt |*******************************************************")
# print("* 7 | Exit |*******************************************************")
# print("********************************************************************************")
#
# answer = input("\n\nEnter Option: ")
# if answer == "1":
# clear_clipboard()
# elif answer == "2":
# copy_to_clipboard(sha256_hash)
# elif answer == "3":
# main_loop() # Restart the main loop
# elif answer == "4":
# verify_hash() # Call the verify_hash function
# elif answer == "5":
# encrypt_text()
# elif answer == "6":
# decrypt_text()
# elif answer == "7":
# exit() # Exit program
# else:
# print("\nInvalid Input.")
def verify_hash():
try:
input_hash = input("\nEnter the hash to verify: ")
original_text = input("\nEnter the original text to verify against the hash: ")
salt = input("Enter the salt value used during hashing: ") # Ask for the salt
computed_hash = hashlib.sha256((original_text + salt).encode()).hexdigest() # Apply the salt
if computed_hash == input_hash:
print("\n\nHash successfully verified.")
else:
print("\n\nVerification unsuccessful. Hash does not match.")
except Exception as e:
print(f"\n\nError during verification: {e}")
def main_loop():
counter = 0
while True:
text = getpass.getpass(prompt="\n\n. . . . . .")
if text == "exit":
break
counter += 1
print(f"\n--- session {counter} ---")
try:
# Adding a salt for security
salt = input("Enter salt value:")
sha256_hash = hashlib.sha256((text + salt).encode()).hexdigest()
print("\n\nOutput:\n")
print("-" * 80)
print(sha256_hash)
print("-" * 80)
print_menu(sha256_hash)
except Exception as e:
print(f"\nError: {e}")
input("\nPress Enter To Exit.")
# ASCII Art
print("\n")
print(" /\\")
print(" /__\\")
print(" /\\ /\\")
print(" /__\\/__\\")
print(" /\\ /\\")
print(" /__\\ /__\\")
print(" /\\ /\\ /\\ /\\")
print(" /__\\/__\\/__\\/__\\")
main_loop()