################# ###EBAUCHE N°1### ################# minuscules = 'abcdefghijklmnopqrstuvwxyz' majuscules = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' x=int(input("Choisissez votre clé: ")) chaine=str(input("Ecrivez votre texte à coder: ")) #Fonction de déchiffrage def rotation(chaine, x): return chaine[x:] + chaine[:x] def index(c, chaine): for i in range(len(chaine)): if (c == chaine[i]): return i return -1 def chiffre(): chaine=chiffre2() r_min = rotation(minuscules, x) r_maj = rotation(majuscules, x) resultat = '' for lettre in chaine: if lettre in minuscules: resultat = resultat + r_min[index(lettre, minuscules)] elif lettre in majuscules: resultat = resultat + r_maj[index(lettre, majuscules)] else: resultat = resultat + lettre LabelR.configure(text=resultat) def chiffre2(): mot=TexteX.get() return mot #Fonction de déchiffrage def rotation2(chaine_cryptée, x): return chaine[:x] + chaine[x:] def index2(c,chaine_cryptée ): for i in range(len(chaine)): if (c == chaine[i]): return i return -1 def dechiffre(): r_min = rotation2(minuscules, -x) r_maj = rotation2(majuscules, -x) resultat2 = '' for lettre in chaine: if lettre in minuscules: resultat2 = resultat2 + r_min[index2(lettre, minuscules)] elif lettre in majuscules: resultat2 = resultat2 + r_maj[index2(lettre, majuscules)] else: resultat2 = resultat2 + lettre return resultat2 def dechiffre2(): TexteX.set(dechiffre()) chaine_decryptée=dechiffre() print(chaine_decryptée) '''Tkinter''' from tkinter import* #Création de le fenetre fenetre = Tk() fenetre.title("Codage et décodage") fenetre.geometry("700x500") Titre= Label(fenetre, text="CODER ET DECODER EN CESAR", fg ='blue', bg ='white', font=("Helvetica", 20)) Titre.grid(row=0, sticky=N) #Zone de saisie du texte Texte1= Entry(fenetre, bg ='bisque', fg='maroon',textvariable=TexteX) Texte1.grid(row=4, sticky=E) Texte1label= Label(fenetre, text="Message à coder: ", fg ='black', bg ='white', font=("Helvetica", 13)) Texte1label.grid(row=5,sticky=E) #Zone de saisie de la clé de codage Key= Entry(fenetre, bg ='bisque', fg='maroon') Key.grid(row=6,sticky=E) Key2 = Label(fenetre, text='clé: ', fg ='black', bg ='white', font=("Helvetica", 11)) Key2.grid(row=7,sticky=E) #Bouton de codage bouton2 = Button(fenetre,text='Coder',command=chiffre) bouton2.grid(row =8, sticky =E) #Bouton de décodage bouton3 = Button(fenetre,text='Décoder', command=dechiffre) bouton3.grid(row=9, sticky=E) # Zone d'affichage du résultat LabelR= Label(fenetre, text="Message codé: ", fg ='black', bg ='white', textvariable=chaine_cryptée) LabelR.grid(row=10,sticky=E) #Bouton pour quitter bouton1 = Button(fenetre,text='Quitter',command=fenetre.destroy) bouton1.grid(row=12,sticky=E)