-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtbash Cipher.py
More file actions
77 lines (52 loc) · 1.7 KB
/
Atbash Cipher.py
File metadata and controls
77 lines (52 loc) · 1.7 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
"""
Here are two alphabets, both English and Greek
"""
Alphabet = "ABCDEFGHIJKLMNOPQRSTUWXYZΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"
AlphabetRVS = "ZYXWUTSRQPONMLKJIHGFEDCBAΩΨΧΦΥΤΣΡΠΟΞΝΜΛΚΙΘΗΖΕΔΓΒΑ"
'''
User's message
'''
message = input("Enter your message:").upper()
def encryption():
encryption_text = ''
'''
Convert Alphabet to Alphabet reversed,space included.
'''
for i in range(len(message)):
if message[i] == chr(32):
encryption_text += " "
else:
for j in range(len(Alphabet)):
if message[i] == Alphabet[j]:
encryption_text += AlphabetRVS[j]
break
print("Encrypted message: {}".format(encryption_text))
def decryption():
dencryption_text = ''
'''
Convert Alphabet reversed to Alphabet ,space included.
'''
for i in range(len(message)):
if message[i] == chr(32):
dencryption_text += " "
else:
for j in range(len(AlphabetRVS)):
if message[i] == AlphabetRVS[j]:
dencryption_text += Alphabet[j]
break
print("Decrypted message: {}".format(dencryption_text))
def main():
'''
User's choice for encryption or decryption.
'''
choice = int(input("Please enter:\n 1:for encryption\n 2:for decryption \n"))
if choice == 1:
print("---Encryption---")
encryption()
elif choice == 2:
print("---Decryption---")
decryption()
else:
print("Wrong choice. Try again!")
if __name__ == '__main__':
main()