summaryrefslogtreecommitdiff
path: root/cesar.py
blob: 93bbc392622466310491a66eb837bc6ebc67a311 (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
#!/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 pour chiffrer un message", "- d pour dechiffrer un message", "- q pour 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 += 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()