-
Notifications
You must be signed in to change notification settings - Fork 0
/
Caesar_Encryption_Decryption.py
43 lines (35 loc) · 1.07 KB
/
Caesar_Encryption_Decryption.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
SIZE = 26
def getMode():
print("Brute Force for Caesar Cipher")
mode = input().lower()
return mode
def getMessage():
print("Enter message")
return input()
def getConvertedMessage(mode, message, key):
if mode[0] == 'd':
key = -key
translated = ''
for symbol in message:
if symbol.isalpha():
num = ord(symbol)
num += key
if symbol.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif symbol.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26
translated += chr(num)
else:
translated += symbol
return translated
mode = getMode()
message = getMessage()
print("Translated")
for key in range(1, SIZE + 1):
print(key, getConvertedMessage(mode, message, key))