#Activity 14.1.13 - Vignenere cipher

def vigenere_cipher(message, keyword):
# 
    characters = ['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']

    keyList = []
    #

    keyLength = 0
    while keyLength < len(message):
        #
        for char in keyword:
            if keyLength < len(message):
                keyList.append(char)
                keyLength += 1
                
    #
    encryptedChars = [] 

    encryptedCharIndexValue = 0
    keyIncrement = 0
    #
    for char in message:
        #
        encryptedCharIndexValue = characters.index(keyList[keyIncrement]) + characters.index(char)

        while encryptedCharIndexValue > 25:
            encryptedCharIndexValue = encryptedCharIndexValue - 26 

        #
        encryptedChars.append(characters[encryptedCharIndexValue])
       
        keyIncrement += 1

    return ''.join(encryptedChars)
    #

### main program ###
messageToEncrypt = input('Message: ')
keyword = input('Enter keyword: ')
encryptedMessage = vigenere_cipher(messageToEncrypt, keyword)
print(encryptedMessage)
