def encode(plaintext, shift):
    """Encode plaintext
    Encode the message with a given shift key. Offset each character
    in the message by 'shift' number of letters in the alphabet
    """

    ciphertext = ""

    # shift each character
    for x in plaintext:
        if 97 <= ord(x) <= 122:       # if character is alphabetic lowercase
            ciphertext += chr((ord(x) - 97 + shift) % 26 + 97)
        elif 65 <= ord(x) <= 90:      # if character is alphabetic uppercase
            ciphertext += chr((ord(x) - 65 + shift) % 26 + 65)
        else:                         # non-alphabetic characters do not change
            ciphertext += x
    return ciphertext