Advertisement
fx16

Cryptage César

Feb 1st, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. texte=input('Quel est le texte à coder ?')
  2. clef=int(input('Quelle est la clef ?'))
  3.  
  4. caractères_accent=['é','è','ê','ë','à','â','ù','û','ô','ç','œ','æ']
  5. caractères_sans_accent=['e','e','e','e','a','a','u','u','o','c','oe','ae']
  6.  
  7. ponctuation=[',',';',':','.','!','?','-','/']
  8. sans_ponctuation=[' ',' ',' ',' ',' ',' ',' ',' ']
  9.  
  10. for i in range(12):
  11.     texte=texte.replace(caractères_accent[i],caractères_sans_accent[i])
  12.  
  13. for j in range(8):
  14.     texte=texte.replace(ponctuation[j],sans_ponctuation[j])
  15.  
  16. texte=texte.upper()
  17.  
  18. #texte=texte.replace(' ','') # pour suppripmer les espaces
  19.  
  20. print(texte)
  21.  
  22. def César(texte,clef):
  23.     texte_crypté=''
  24.     for lettre in texte:
  25.         if lettre==' ':
  26.             texte_crypté=texte_crypté+' '
  27.         else:
  28.             rang=ord(lettre)-65
  29.             rang_codé=(rang+clef)%26
  30.             lettre_cryptée=chr(rang_codé+65)
  31.             texte_crypté=texte_crypté+lettre_cryptée
  32.     return texte_crypté
  33.    
  34. print(César(texte,clef))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement