Overblog Tous les blogs Top blogs Emploi, Enseignement & Etudes Tous les blogs Emploi, Enseignement & Etudes
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

Ce blog est fait pour aider à la compréhension des maths et ses mises en application dans différents langages de programmation ( Algobox, Python, calculatrice Ti83)

chiffrement de César

def indice(CHA):
    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']
    ind=liste.index(CHA) 
    return(ind)


def crypterLettre(CHA,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']
    Cle=int(CLEF)
    sortie=indice(CHA)
    intcrypte = sortie + Cle
    intcrypte=intcrypte%26
    return(liste[intcrypte])

def crypterTexte(CHAINE,CLEF):
    Cle=int(CLEF)
    chaine=CHAINE.upper()
    textefinal=[]
    for lettre in chaine:
        if lettre == ' ':
            textefinal.append(' ')
        else :
            textefinal.append(crypterLettre(lettre,CLEF))
    return "".join(textefinal)
        
texte=input("Quel est le texte a crypter ?: ")
cle=-1
while (cle<1 or cle>25):
    CLEF=input("Quel est la clé du cryptage ?: ")
    cle=int(CLEF)
sortie=crypterTexte(texte,cle)
print(sortie)

Retour à l'accueil
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article