PopKhorn

Decrypteur_Code_César

May 28th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. listeM = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  2. listeM += listeM
  3. listem = 'abcdefghijklmnopqrstuvwxyz'
  4. listem += listem
  5. listex = ',;:!?.@/§%¨^*£$¤}=+°)]^\'_`|-[({"~&0123456789çéèàùûêôîâ'
  6. listex += listex
  7.  
  8.  
  9. message = input('Entrez votre message : ')
  10.  
  11.  
  12.  
  13. def dechiffrage_lettre(lettre,listeM,listem,listex,cle):
  14. for i in range(len(listeM)):
  15. if listeM[i]==lettre:
  16. return str(listeM[i-cle])
  17. elif lettre==' ': #au cas ou il y a un espace
  18. return ' '
  19. for m in range (len(listem)):
  20. if listem[m]==lettre:
  21. return str(listem[m-cle])
  22. elif lettre==' ': #au cas ou il y a un espace
  23. return ' '
  24. for x in range (len(listex)):
  25. if listex[x]==lettre:
  26. if lettre=='é':
  27. return str(listem[4-cle])
  28. else:
  29. if lettre=='è':
  30. return str(listem[4-cle])
  31. else:
  32. if lettre=='ê':
  33. return str(listem[4-cle])
  34. else:
  35. if lettre=='à':
  36. return str(listem[0-cle])
  37. else:
  38. if lettre=='â':
  39. return str(listem[0-cle])
  40. else:
  41. if lettre=='ù':
  42. return str(listem[20-cle])
  43. else:
  44. if lettre=='û':
  45. return str(listem[20-cle])
  46. else:
  47. if lettre=='ô':
  48. return str(listem[14-cle])
  49. else:
  50. if lettre=='î':
  51. return str(listem[8-cle])
  52. else:
  53. if lettre=='ç':
  54. return str(listem[2-cle])
  55. else:
  56. return str(listex[x])
  57. elif lettre==' ': #au cas ou il y a un espace
  58. return ' '
  59.  
  60.  
  61. #########################################
  62. #Pour un message dont on connait la clé de decryptage
  63. #########################################
  64.  
  65. cle = int(input('Entrez votre clef : '))
  66.  
  67. message_dechiffre = str()
  68. for lettre in message:
  69. message_dechiffre += dechiffrage_lettre(lettre,listeM,listem,listex,cle)
  70.  
  71. print(message_dechiffre)
  72.  
  73. ##########################################
  74. #Pour un message dont on ne connait pas la clé de décryptage (si vous décommentez cette partie, il faut commenter l'autre)
  75. ##########################################
  76.  
  77. #for cle in range(26):
  78. # message_dechiffre = str()
  79. # for lettre in message:
  80. # message_dechiffre += dechiffrage_lettre(lettre,listeM,listem,listex,cle)
  81. # print(cle)
  82. # print(message_dechiffre)
Advertisement
Add Comment
Please, Sign In to add comment