-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryptor.py
88 lines (73 loc) · 2.95 KB
/
encryptor.py
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
from cryptography.fernet import Fernet
from time import sleep
from os import system
from colorama import Fore, Style
system("pip install -r requirements.txt")
system("cls || clear")
while True:
print(Fore.LIGHTGREEN_EX + "\tWELCOME TO THE ENCRYPTER" + Style.RESET_ALL +
Fore.LIGHTRED_EX + "\n Choose Your File And Encrypt It\n\t Or Decrypt It")
sleep(1)
print("""{}
\t0giv Encrypter
""".format(Fore.RED, Style.RESET_ALL))
sleep(1)
print(Fore.LIGHTGREEN_EX + "{/} " + Style.RESET_ALL + "By " +
Fore.RED + Style.BRIGHT + "0giv\n" + Style.RESET_ALL)
sleep(1)
key = Fernet.generate_key()
menu = int(input(Fore.LIGHTMAGENTA_EX +
" \t1- Encrypt It\n \t2- Decrypt It\n\t3- Exit\n" + Fore.LIGHTYELLOW_EX + "\n Entry: "))
if menu == 1:
savekey = input(
str("Where Would Like To Save Key File?(Use '//'): " + Style.RESET_ALL))
choosenfile = input(
str("Enter The File Path With File Extension(Use '//'): " + Style.RESET_ALL))
encryptedfilepath = input(
str(Fore.LIGHTWHITE_EX + "Where Would Like To Save Encrypted File(With Extention)?(Use '//'): " + Style.RESET_ALL))
system("cls||clear")
with open(f"{savekey}", "wb") as keyfile:
keyfile.write(key)
sleep(1)
print(Fore.RED + "\n\tKey File Created" + Style.RESET_ALL)
with open(f"{savekey}", "rb") as key_file:
key = key_file.read()
sleep(1)
f = Fernet(key)
with open(f"{choosenfile}", "rb") as orginal_file:
orginal = orginal_file.read()
encrypt = f.encrypt(orginal)
with open(f"{encryptedfilepath}", "wb") as encfile:
encfile.write(encrypt)
sleep(1)
print(Fore.LIGHTBLACK_EX + "\n\tEnc File Created" + Style.RESET_ALL)
sleep(2)
system("cls || clear")
elif menu == 2:
savekey = input(
str("Where Is The Key File?(Use '//'): " + Style.RESET_ALL))
enc_file = input(
str(Fore.LIGHTGREEN_EX + "Enter The Encrypted File(Use '//'): "))
decryptfile = input(
str("Where Would Like To Save The Decrypted File(Use '//'): " + Style.RESET_ALL))
with open(f"{savekey}", "rb") as key_file:
key = key_file.read()
sleep(1)
token = Fernet(key)
with open(f"{enc_file}", "rb") as encrypted_file:
encrypted = encrypted_file.read()
decrypt = token.decrypt(encrypted)
with open(f"{decryptfile}", "wb") as decryptedfile:
decryptedfile.write(decrypt)
elif menu == 3:
sleep(1)
print(Fore.RED + "Exiting..." + Style.RESET_ALL)
sleep(2)
system("cls || clear")
break
else:
sleep(1)
print(Fore.RED + "WRONG ENTRY BUDDY!" + Style.RESET_ALL)
sleep(2)
system("cls || clear")
continue