Python de chiffrement de vigenere d'aller plus loin que nécessaire?

Je suis d'essayer de créer le chiffrement de vigenere en python et il semble y avoir un problème. Voici mon code de cryptage:

def encryption():
    plaintext=input("Please enter the message you wish to encode.")
    #This allows the user to enter the message they wish to encrypt.
    keyword=input("Please enter your keyword, preferably shorter than the plaintext.")
    #This allows the user to enter a keyword.
    encoded=""
    #This creates a string for the user to input the encrypted message to.
    while len(keyword)<len(plaintext):
        #This begins a while loop based on the fact that the length of the keyword is shorter than the length of the plaintext.
        keyword+=keyword
        #This repeats the keyword.
        if len(keyword)>len(plaintext):
            #This sees if the string length of the keyword is now longer than the string length of the plaintext.
            newkey=keyword[:len(plaintext)]
            #This cuts the string length of the keyword
    for c in range(len(plaintext)):
        char=ord(plaintext[c])
        temp=ord(keyword[c])
        newchar=char+temp
        if newchar>ord("Z"):
            newchar-=26
        newnewchar=chr(newchar)
        encoded+=newnewchar
    print(encoded)

Je n'arrive pas à trouver le problème avec lui, mais quand je suis entrer dans le texte "bonjour" et le mot "salut" elle avec les symboles suivants: ¶º»½. Je pense que l'ajout de la boucle for peut être aller trop loin.

InformationsquelleAutor Asterus | 2014-11-05