Python 3 Simple Xor Pipe/CLI Program
Does anyone know why I am seeing the character 8 appended to the output of xor decrypted data?


The statement echo lol pipes lol\n\r to Python, which encodes the line breaks as ;_ which is decoded into an 8. Unfortunately echo -n doesn't work here but adding .strip() to the input data in the Python script fixes this issue.

PEP8 is Python's internal coding standards which specify how line breaks and code should be structured: https://www.python.org/dev/peps/pep-0008/ . The guide is very long; you can use autopep8 to auto-format the code.

    if raw:
        ret = xor(data, key)
        print(str(ret))
    else:
        if is_base64(data):
            # print('is base64')
            decoded = base64.b64decode(data).decode()
            ret = xor(decoded, key)
            print(ret)
        else:
            # print('is not base64')
            ret = xor(data, key)
            encoded = base64.b64encode(bytes(ret, "utf-8"))
            print(encoded.decode())


I would simplify the nested if-statements and add a return to print(str(ret)) then the is_base64 could be unindented, or I would set a variable called decoded to the final string to print, then print it out at the end of the if/elif loop.

is_base64(s) could just run base64.b64decode(data).decode() and return False if any exceptions were thrown during decoding instead of the regex.

I would remove the commented out code such as # print('is base64').