ajout de tous les cours et TP préparés cet été
This commit is contained in:
38
Sécurité/exemples/code_inverse.py
Executable file
38
Sécurité/exemples/code_inverse.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Jan 7 20:03:19 2021
|
||||
|
||||
@author: pjoulaud
|
||||
"""
|
||||
|
||||
def codage_inverse(texte):
|
||||
"""
|
||||
Fonction qui code un texte suivant la méthode de codage inverse
|
||||
(A <=> Z, B <=> Y, C <=> X, ...).
|
||||
Arguments ::
|
||||
- texte : message à coder de type str
|
||||
Renvoie ::
|
||||
- texte_chiffre : le message codé de type str
|
||||
>>> codage_inverse('VENI, VIDI, DICI')
|
||||
FWNS, FSXS, XSYS
|
||||
>>> codage_inverse(codage_inverse('VENI, VIDI, DICI'))
|
||||
VENI, VIDI, DICI
|
||||
"""
|
||||
texte_chiffre = ""
|
||||
for lettre in texte :
|
||||
if lettre in ('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'):
|
||||
ordre_dans_alphabet = 26-ord(lettre)-ord('A')
|
||||
texte_chiffre += chr(ordre_dans_alphabet%26+ord('A'))
|
||||
else:
|
||||
texte_chiffre += lettre
|
||||
return texte_chiffre
|
||||
|
||||
if __name__ == '__main__':
|
||||
#ACTION DE CODAGE
|
||||
toto=codage_inverse('VENI, VIDI, DICI')
|
||||
print(toto)
|
||||
#ACTION DE CODAGE
|
||||
toto=codage_inverse(toto)
|
||||
print(toto)
|
||||
Reference in New Issue
Block a user