-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubstitution.py
More file actions
69 lines (64 loc) · 1.73 KB
/
substitution.py
File metadata and controls
69 lines (64 loc) · 1.73 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
implementation de la methode de chiffrement par substitution
Il consiste a faire correspondre chaque lettre de l'alphabet
a une autre lettre sans regle definie (aleatoirement).
@author : Abdoulaye NIANG
"""
table = {
'A':'V',\
'B':'H',\
'C':'K',\
'D':'N',\
'E':'F',\
'F':'Q',\
'G':'T',\
'H':'W',\
'I':'S',\
'J':'M',\
'K':'P',\
'L':'A',\
'M':'L',\
'N':'G',\
'O':'D',\
'P':'R',\
'Q':'Z',\
'R':'B',\
'S':'J',\
'T':'Y',\
'U':'E',\
'V':'X',\
'W':'C',\
'X':'O',\
'Y':'U',\
'Z':'I'
}
def chiffre_caractere(caractere):
return table.get(caractere)
def chiffre_message(message):
message_crypte = []
for caractere in message:
if caractere == " " or caractere == "\t" or caractere =="\n":
caractere_crypte = caractere
else:
caractere = caractere.upper()
caractere_crypte = chiffre_caractere(caractere)
message_crypte.append(caractere_crypte)
message_crypte = "".join(message_crypte)
return message_crypte
#creation de la table de correspondance de decryptage par correspondance a celle de cryptage
d_table = {}
for cle in table:
d_table[table.get(cle)] = cle
def dechiffre_caractere(caractere):
return d_table.get(caractere)
def dechiffre_message(message):
message_decrypte = []
for caractere in message:
if caractere == " " or caractere == "\t" or caractere =="\n":
caractere_decrypte = caractere
else:
caractere = caractere.upper()
caractere_decrypte = dechiffre_caractere(caractere)
message_decrypte.append(caractere_decrypte)
message_decrypte = "".join(message_decrypte)
return message_decrypte