def rolling_xor(shellcode: bytes, decode: bool=False) -> bytes:
    """ Perform a rolling xor encoding scheme on `shellcode`.

    :param shellcode: bytes object; data to be [en,de]coded
    :param decode: boolean, decrypt previously xor'd data
    :return: bytes object
    """
    shellcode = bytearray(shellcode)

    if decode:
        shellcode.reverse()
        encoded_payload = bytearray()

        for i, byte in enumerate(shellcode):
            if i == len(shellcode) - 1:
                encoded_payload.append(shellcode[i])  # last byte doesn't need xor'd, common to system call Ox80 generally
            else:
                encoded_payload.append(shellcode[i] ^ shellcode[i + 1])

        encoded_payload.reverse()
    else:
        encoded_payload = bytearray([shellcode.pop(0)])  # first byte left as is in the ciphertext

        for i, byte in enumerate(shellcode):
            encoded_payload.append(byte ^ encoded_payload[i])

    return bytes(encoded_payload)