summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar.py59
1 files changed, 44 insertions, 15 deletions
diff --git a/cesar.py b/cesar.py
index 15d7ce2..65fef7f 100644
--- a/cesar.py
+++ b/cesar.py
@@ -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()