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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #################
###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) |
Partager