-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypto-cesar.py
More file actions
30 lines (22 loc) · 1.01 KB
/
Copy pathdecrypto-cesar.py
File metadata and controls
30 lines (22 loc) · 1.01 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
# Le chiffre de César (décrypter)
# Il s'agit juste d'une version interactive et optimisée de celle que j'ai proposé sur Hackinscience
import string
# Décryptage d'une chaîne de caractère s avec key pour décalage
def caesar_cypher_decrypt(s, key):
key = key % 26
alphabet_strange_min = string.ascii_lowercase[key:] + string.ascii_lowercase[:key]
alphabet_strange_maj = string.ascii_uppercase[key:] + string.ascii_uppercase[:key]
decoded = ""
for c in s:
if c in alphabet_strange_min:
index = alphabet_strange_min.find(c)
decoded = decoded + string.ascii_lowercase[index]
elif c in alphabet_strange_maj:
index = alphabet_strange_maj.find(c)
decoded = decoded + string.ascii_uppercase[index]
else:
decoded = decoded + c
return decoded
string_decoded = input("Le texte à décoder: ")
code = int(input("Le décalage (3 pour César): "))
print(f"\nLe texte est: {caesar_cypher_decrypt(string_decoded, code)}")