-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaesars.py
41 lines (29 loc) · 983 Bytes
/
caesars.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
mode = str(raw_input("Do you want to encrypt or decrypt ?"))
message = str(raw_input("Input the message : "))
key = int(raw_input("Enter the key : "))
translated = ''
SYMBOLS = 'abcdefghijklmnopqrstuvwxyz'
if message.isupper():
alp = 1
message = message.lower()
else:
alp =0
for symbol in message:
if symbol in SYMBOLS:
symbolIndex = SYMBOLS.find(symbol)
if mode == 'encrypt':
translatedIndex = symbolIndex + key
elif mode == 'decrypt':
translatedIndex = symbolIndex - key
if translatedIndex >= len(SYMBOLS):
translatedIndex = translatedIndex - len(SYMBOLS)
elif translatedIndex < 0:
translatedIndex = translatedIndex + len(SYMBOLS)
translated = translated + SYMBOLS[translatedIndex]
else:
translated = translated + symbol
print("Your Translated text is : ")
if alp == 1 :
print(translated.upper())
else:
print(translated)