diff options
| author | jerome <jerome@xlinfo.fr> | 2024-09-10 00:56:35 +0200 |
|---|---|---|
| committer | jerome <jerome@xlinfo.fr> | 2024-09-10 00:56:35 +0200 |
| commit | 075b82f4363ca80dac8a2ac7d66cde9050e2a155 (patch) | |
| tree | 9a957e31dc918fb6a26176d232747f004d25db6e /cesar.py | |
| parent | 67c94bcdabad901f1e690d373d30417847f8009c (diff) | |
| download | python-075b82f4363ca80dac8a2ac7d66cde9050e2a155.tar.gz python-075b82f4363ca80dac8a2ac7d66cde9050e2a155.zip | |
cesar.py
Diffstat (limited to 'cesar.py')
| -rw-r--r-- | cesar.py | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -1,20 +1,19 @@ -liste=['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','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','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','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'] +def decalage(lettre,clef): + liste=['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','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','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','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'] -def decalage(lettre,liste,clef): - for i in range(len(liste)): - if lettre not in liste: - return lettre - elif lettre==liste[i]: - return str(liste[i+clef]) + if lettre not in liste: + return lettre + else: + return liste[liste.index(lettre)+clef] -message_chiffre = str() +msg_chiffre = str() while True: - message = input('Entrez le texte à chiffrer (q pour quitter) : ') - if message == "q" or message =="Q": + msg = input('Entrez le texte à chiffrer (q pour quitter) : ') + if msg.lower() == "q": print("bye") exit() clef = int(input('Entrez votre clef : ')) - for lettre in message: - message_chiffre += decalage(lettre,liste,clef) - print(message_chiffre) - message_chiffre="" + for lettre in msg: + msg_chiffre += decalage(lettre,clef) + print(msg_chiffre) + msg_chiffre = "" |
