coder_du_viginere.py

Created by jerem-jarsaillon

Created on January 23, 2024

1.24 KB


def prepare(TexteClair):
    li1=["âà","éèêë","îï","","ûü",""]
    li2=["A","E","I","O","U","C"]
    i=0
    # Remplacement des caractères accentués éventuels
    for mot in li1:
       repl=li2[i]
       for lettre in mot:
           TexteClair=TexteClair.replace(lettre,repl)
       i+=1      
    for lettre in "',-;:!?.":   # Suppression des signes de ponctuation
        TexteClair=TexteClair.replace(lettre,"")
    TexteClair=TexteClair.upper()    # Passage en majuscules
    return TexteClair

Carre=[]
ligne=[]
for j in range(26):
    for i in range(26):
        ligne.append(chr(65+(i+j)%26))
    Carre.append(ligne)
    ligne=[]


TexteClair=str(input("entrez le texteclair"))
TexteClair=prepare(TexteClair)
lg_tc=len(TexteClair)
Cle=str(input("entrez la clef"))
lg_C=len(Cle)
bl=0                   
TexteCrypte=""


for i in range(lg_tc):
    lettre=TexteClair[i]
    if lettre==" ":
        bl+=1
        TexteCrypte+=" "
    else:
        j=(i-bl)%lg_C
        j=ord(Cle[j])-65
        h=ord(lettre)-65
        TexteCrypte+= Carre[h][j]


print ("             Texte de départ :")
print (TexteClair)
print
print ("             Clé :")
print (Cle)
print
print ("             Texte crypté :")
print (TexteCrypte)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.