summaryrefslogtreecommitdiff
path: root/cesar.py
blob: 1940172d15b525e32f31ef867005f14aeabb942b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python

import string


def decalage(char, key):
    liste = list(string.ascii_lowercase)*2 + list(string.ascii_uppercase)*2
    #print(liste)
    if char not in liste:
        return char
    else:
        return liste[liste.index(char)+key]

# print(decalage("a",3))


print("********************")
print("Chiffrement de César")
print("********************")

menu = ["c) Chiffrer un message", "d) Dechiffrer un message", "q) Quitter"]

while True:
    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 = msgChiffre + decalage(lettre,clef)
                #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(25,0,-1):
                for lettre in msgChiffre:
                    msg += decalage(lettre, clef)
                print(f"rot{26-clef} : {msg}")
                msg = ""
            print("********************")
        case "q":
            print("bye")
            exit()