for keyword hello h e l o a b c d f g i j k m n p q r s t u v w x y z and map vertically mixedkeywordcollege university true doctest normalizewhitespace a c b a c i d p e u f z g o h b i j j q k v l l m d n k o r p w q e r f s m t s u x v g w h x n y t z y xkjgufmjst mixedkeywordcollege university false doctest normalizewhitespace xkjgufmjst create a list of unique characters in the keyword their order matters it determines how we will map plaintext characters to the ciphertext the number of those unique characters will determine the number of rows create a shifted version of the alphabet create a modified alphabet by splitting the shifted alphabet into rows map the alphabet characters to the modified alphabet characters going vertically through the modified alphabet consider columns first if current row the last one is too short break out of loop map current letter to letter in modified alphabet create the encrypted text by mapping the plaintext to the modified alphabet example use for keyword hello h e l o a b c d f g i j k m n p q r s t u v w x y z and map vertically mixed_keyword college university true doctest normalize_whitespace a c b a c i d p e u f z g o h b i j j q k v l l m d n k o r p w q e r f s m t s u x v g w h x n y t z y xkjgufmjst mixed_keyword college university false doctest normalize_whitespace xkjgufmjst create a list of unique characters in the keyword their order matters it determines how we will map plaintext characters to the ciphertext the number of those unique characters will determine the number of rows create a shifted version of the alphabet create a modified alphabet by splitting the shifted alphabet into rows map the alphabet characters to the modified alphabet characters going vertically through the modified alphabet consider columns first if current row the last one is too short break out of loop map current letter to letter in modified alphabet create the encrypted text by mapping the plaintext to the modified alphabet example use
from string import ascii_uppercase


def mixed_keyword(
    keyword: str, plaintext: str, verbose: bool = False, alphabet: str = ascii_uppercase
) -> str:
    
    keyword = keyword.upper()
    plaintext = plaintext.upper()
    alphabet_set = set(alphabet)

    
    
    unique_chars = []
    for char in keyword:
        if char in alphabet_set and char not in unique_chars:
            unique_chars.append(char)
    
    num_unique_chars_in_keyword = len(unique_chars)

    
    shifted_alphabet = unique_chars + [
        char for char in alphabet if char not in unique_chars
    ]

    
    modified_alphabet = [
        shifted_alphabet[k : k + num_unique_chars_in_keyword]
        for k in range(0, 26, num_unique_chars_in_keyword)
    ]
  
    mapping = {}
    letter_index = 0
    for column in range(num_unique_chars_in_keyword):
        for row in modified_alphabet:
            
            if len(row) <= column:
                break

            
            mapping[alphabet[letter_index]] = row[column]
            letter_index += 1

    if verbose:
        print(mapping)
    
    return "".join(mapping[char] if char in mapping else char for char in plaintext)


if __name__ == "__main__":
    
    print(mixed_keyword("college", "UNIVERSITY"))