-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypto-polybe.py
33 lines (26 loc) · 918 Bytes
/
decrypto-polybe.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
# Le carré de Polybe (décrypter)
# j'ai utilisé la variante avec des chiffres pour éviter la confusion I/J
# cette fonction fait le décryptage
def Unpolybe(phrase):
grille = [
["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", "0", "1", "2", "3"],
["4", "5", "6", "7", "8", "9"]
]
i = 0
unpolybe = ""
while i != len(phrase):
if phrase[i].isdigit():
if phrase[i + 1].isdigit():
unpolybe = unpolybe + grille[int(phrase[i]) - 1][int(phrase[i + 1]) - 1]
i = i + 2
else:
unpolybe = unpolybe + phrase[i]
i = i + 1
return unpolybe
# programme principal
phrase = input("Texte a décrypter: ")
print(f"Texte décrypté: {phrase}")