The while loop doesn't end but the condition is met

I'm trying to code vigenere cypher so I need to have two lists of the same length. I thought everything will be okay with my solution but the while loop doesn't despite of the fact than condition is met. Because of that I got two list with different numbers of letters. Why this works like that and how to improve that. I am new programmer who learnt from books, so I haven't ever seen that while loop doesn't work properly. My code:

plaintext = "This is secret message"
plaintext = plaintext.upper()
key = "secret"
key = key.upper()
def encrypt_vigenere2( key, plaintext ):
    a = []
    b= []
    i = 0
    for letter in (plaintext):
        if letter != " ":
            a.append(letter)
    while i<len(a):
        for element in key:
            if element != " ":
                b.append(element)
                i +=1
    return a,b
print(encrypt_vigenere2(key,plaintext))


Post a Comment

0 Comments