summaryrefslogtreecommitdiff
path: root/cesar.py
diff options
context:
space:
mode:
authorjerome <jerome@xlinfo.fr>2024-09-10 00:56:35 +0200
committerjerome <jerome@xlinfo.fr>2024-09-10 00:56:35 +0200
commit075b82f4363ca80dac8a2ac7d66cde9050e2a155 (patch)
tree9a957e31dc918fb6a26176d232747f004d25db6e /cesar.py
parent67c94bcdabad901f1e690d373d30417847f8009c (diff)
downloadpython-075b82f4363ca80dac8a2ac7d66cde9050e2a155.tar.gz
python-075b82f4363ca80dac8a2ac7d66cde9050e2a155.zip
cesar.py
Diffstat (limited to 'cesar.py')
-rw-r--r--cesar.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/cesar.py b/cesar.py
index ca6fb12..e9381d7 100644
--- a/cesar.py
+++ b/cesar.py
@@ -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 = ""