summaryrefslogtreecommitdiff
path: root/cesar.py
blob: e9381d72918cf10dbc63f0bcaa4f4bfb7472ec0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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']

    if lettre not in liste:
        return lettre
    else:
        return liste[liste.index(lettre)+clef]

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 = ""