import base64


def pw_encode(key, clear):
    """Vigenère cipher encoder.

    Lifted from here: https://stackoverflow.com/a/38223403"""

    enc = []
    for i in range(len(clear)):
        key_c = key[i % len(key)]
        enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
        enc.append(enc_c)

    return base64.urlsafe_b64encode(''.join(enc).encode()).decode()