-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (30 loc) · 1.01 KB
/
main.py
File metadata and controls
38 lines (30 loc) · 1.01 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
from ciphers import caesar, vigenere
from utils.text_utils import validate_input, clean_text, print_result
CIPHERS = {
'caesar': caesar,
'vigenere': vigenere,
}
def main():
while True:
cipher_type = input("\nCipher type (caesar/vigenere): ").lower()
if cipher_type not in CIPHERS:
print("Not supported yet."); continue
text = clean_text(input("Text: "))
key = input("Key: ")
try:
validate_input(text, key)
except ValueError as e:
print(e); continue
op = input("(E)ncrypt or (D)ecrypt? ").upper()
module = CIPHERS[cipher_type]
if op == 'E':
result = module.encrypt(text, key)
print_result("ENCRYPTED", text, result)
elif op == 'D':
result = module.decrypt(text, key)
print_result("DECRYPTED", text, result)
again = input("\nAnother operation? (y/n): ")
if again.lower() != 'y':
break
if __name__ == "__main__":
main()