diff options
| author | jerome <jerome@xlinfo.fr> | 2024-09-10 19:41:13 +0200 |
|---|---|---|
| committer | jerome <jerome@xlinfo.fr> | 2024-09-10 19:41:13 +0200 |
| commit | 3ec99e31c501e8108092b2495191110fb91e7550 (patch) | |
| tree | f9fd8b237daccb9d83e0e1a015f9ff6fa5362854 | |
| parent | 2173ed5fe5e5a55d0f0148011ba6fb460295fdd7 (diff) | |
| download | python-3ec99e31c501e8108092b2495191110fb91e7550.tar.gz python-3ec99e31c501e8108092b2495191110fb91e7550.zip | |
cesar.py
| -rw-r--r-- | cesar.py | 59 |
1 files changed, 44 insertions, 15 deletions
@@ -1,20 +1,49 @@ +#!/usr/bin/env python + import string -def decalage(lettre,clef): - liste=list(string.ascii_lowercase)*2 + list(string.ascii_uppercase)*2 - if lettre not in liste: - return lettre + +def decalage(char, key): + liste = list(string.ascii_lowercase)*2 + list(string.ascii_uppercase)*2 + if char not in liste: + return char else: - return liste[liste.index(lettre)+clef] + return liste[liste.index(char)+key] + +# print(decalage("a",3)) + + +print("********************") +print("Chiffrement de César") +print("********************") + +menu = ["- c pour chiffrer un message", + "- d pour dechiffrer un message", "- q pour quitter"] -msg_chiffre = str() while True: - 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 msg: - msg_chiffre += decalage(lettre,clef) - print(msg_chiffre) - msg_chiffre = "" + for choix in menu: + print(choix) + rep = input("Votre choix : ") + match rep.lower(): + case "c": + msgChiffre = str() + msg = input("Votre message : ") + clef = int(input("Entrez votre clef (entre 1 et 25) : ")) + for lettre in msg: + msgChiffre += decalage(lettre, clef) + print("\nVotre message chiffré : ", msgChiffre, "\n") + print("***************") + msg = "" + msgChiffre = "" + case "d": + msg = str() + msgChiffre = input("Votre message : ") + for clef in range(1, 26): + for lettre in msgChiffre: + msg += decalage(lettre, clef) + print(f"rot{clef} : {msg}") + msg = "" + print("***************") + case "q": + print("bye") + exit() |
