-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
94 lines (76 loc) · 2.78 KB
/
main.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
89
90
91
92
93
94
import sys
from error_handler import handle_error
# Hack to fix python 3.10 support
if sys.version_info >= (3, 10):
from typing import Mapping
import collections
# imported in prompt_toolkit 1.0.14 which is strictly
# relied on by PyInquirer
collections.Mapping = Mapping # type: ignore
# Importing 3rd Party Libraries
from pyfiglet import Figlet
from PyInquirer import prompt, Separator
from termcolor import colored
# Importing the local functions
from encrypt_code import encrypt_func
from decrypt_code import decrypt_func
from hash_code import hash_func
def main():
# Generating the initial output text with pyfiglet
f = Figlet(font='slant')
credit = colored(' By Arpan Pandey\n', 'yellow', attrs=['bold'])
description = colored(' A tool to hash or encrypt your data easily using Fernet Encryption.'
' It is very easy and intuitive to use.'
' You can also use this on any type of file below 1GB.', 'cyan')
print(colored(f.renderText('Encrypto CLI'), 'green'), credit, description, '\n')
## print(colored('Please enter a password', 'red'))
## print(colored('The encrypted text is: ', 'white') +
## colored(encrypted_text, 'green'))
# Asking the user about which operation do they want to perform
operation: str = prompt([
{
'type': 'list',
'qmark': '🔘',
'name': 'operation',
'message': 'What do you want to do?',
'choices': [
Separator(),
{
'name': 'Hash',
},
{
'name': 'Encrypt',
},
{
'name': 'Decrypt',
},
{
'name': 'Exit',
}
],
}
]).get('operation', None)
if not operation:
# user hit Ctrl+C
return
try:
# Calling the hash function if the selected operation is Hashing
if operation == 'Hash':
# * Called the hashing function
hash_func()
# Calling the Encryption function if the selected operation is encryption
elif operation == 'Encrypt':
# * Called the encryption function
encrypt_func()
# Calling the decryption function if the selected operation is decryption
elif operation == 'Decrypt':
# * Called the decryption function
decrypt_func()
elif operation == 'Exit':
print(colored("goodbye :)", "blue"))
else:
raise NotImplementedError("operation not supported yet.")
except Exception as e:
handle_error(e)
if __name__ == "__main__":
main()