Cryptage de mots/phrases.

Description

Voici un programme qui crypte un mot ou une phrase à l'aide de l'algorythme
de cryptage du chiffre de caesar.

Source / Exemple :


# -*- coding: cp1252 -*-
from Tkinter import *

#--------------fonction qui crypte--------
def crypt():
    mot = entree.get()
    cle = entree1.get()
    alph = ['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']
    c = ""
    i,a = 0,0
    b,o = 0,0
    while len(c) < len(mot):
        if mot[i] in alph:
            if mot[i] == alph[a]:
                b = int(cle[o])
                c = c + alph[(a+b)%53]
                i += 1
                o = (o+1)%len(cle)
            a = (a+1)%53
        else:
            c = c + "*"
            i += 1
    crypter.set(c)

#-------------fonction qui decrypt---------
def decrypt():
    mot = entre.get()
    cle = entre1.get()
    alph = ['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']
    c = ""
    i,a = 0,0
    b,o = 0,0
    while len(c) < len(mot):
        if mot[i] in alph:
            if mot[i] == alph[a]:
                b = int(cle[o])
                c = c + alph[(a-b)%53]
                i += 1
                o = (o+1)%len(cle)
            a = (a+1)%53
        else:
            c = c + "*"
            i += 1
    crypter1.set(c)

#---- Prog Main ----
fen = Tk()
fen.title("By Bouceka")

bou2 = Button(fen,text ='Quitter',fg ='red',command =fen.quit)
bou2.grid(row =8,columnspan =2)

#---- Cryptage -----
Label(fen,text='.: CRYPTAGE :.',fg ='black').grid(row =0,columnspan =2)
Label(fen,text='Texte a crypter : ',fg ='blue').grid(row =1,sticky =W)
Label(fen,text='Clé de cryptage : ',fg ='blue').grid(row =2,sticky =W)

crypter = StringVar()
crypt1 = Entry(fen,textvariable = crypter)
crypt1.grid(row =3,column =1)
crypter.set("Texte crypté")

entree = Entry(fen,fg='brown')
entree.grid(row =1,column =1)

mot = entree.get()

entree1 = Entry(fen,fg ='brown')
entree1.grid(row =2,column =1)

bou1 = Button(fen,text ='Crypter',fg ='blue',command =crypt)
bou1.grid(row = 3)

#---- DECRYPTAGE ----
Label(fen,text ='.: DECRYPTAGE :.',fg ='black').grid(row =4,columnspan =2)

Label(fen,text ='Texte a décrypter : ',fg ='blue').grid(row =5,sticky =W)
Label(fen,text ='Clé de décryptage : ',fg ='blue').grid(row =6,sticky =W)

entre = Entry(fen,fg ='brown')
entre.grid(row =5,column =1)

entre1 = Entry(fen,fg ='brown')
entre1.grid(row =6,column =1)

crypter1 = StringVar()
crypt2 = Entry(fen,textvariable = crypter1)
crypt2.grid(row =7,column =1)
crypter1.set("Texte décrypté")

bou2 = Button(fen,text ='Décrypter',fg ='blue',command =decrypt)
bou2.grid(row =7)

fen.mainloop()
fen.destroy()

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.