-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_cesar.py
More file actions
21 lines (18 loc) · 756 Bytes
/
code_cesar.py
File metadata and controls
21 lines (18 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
texte = input('What do you want encrypted or decrypted? \n')
key = int(input('key ? (you can put a negative key if you want to encrypt) \n'))
def cesar(texte, key):
output = ''
for lettre in texte:
try:
if alphabet.index(lettre) + key > 25:
output += alphabet[alphabet.index(lettre) + key - 26]
except ValueError:
output += lettre
try:
if alphabet.index(lettre) + key <= 25:
output += alphabet[alphabet.index(lettre) + key]
except ValueError:
pass
return output
print(cesar(texte, key))