- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_cesar.py
More file actions
Latest commit
21 lines (18 loc) · 756 Bytes
/
Copy pathcode_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'))
defcesar(texte, key):
output=''
forlettreintexte:
try:
ifalphabet.index(lettre) +key>25:
output+=alphabet[alphabet.index(lettre) +key-26]
exceptValueError:
output+=lettre
try:
ifalphabet.index(lettre) +key<=25:
output+=alphabet[alphabet.index(lettre) +key]
exceptValueError:
pass
returnoutput
print(cesar(texte, key))