import base64


def xor_encode(secret_text):
    """
    Encode text to the xor encoding used by WAS
    """

    # Create a byte array, containing the characters xor'ed with underscore
    xor_byte_array=bytearray([])
    for char in secret_text:
        decimalOfChar=ord(char)
        decimalOfUnderScore=ord('_')

        xor_value = decimalOfChar ^ decimalOfUnderScore
        xor_byte_array.append(xor_value)
   
    ## use base64 to encode it, and then decode those bytes as ascii  
    encoded_secret_text='{xor}' + base64.encodebytes(xor_byte_array).decode('ascii').rstrip()
       
    return encoded_secret_text