38 lines
1.1 KiB
Python
Executable File
38 lines
1.1 KiB
Python
Executable File
#!/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) |