def xor(stream: bytes, key: int) -> bytes:
    """Apply XOR cipher to ``stream`` with ``key``.
    Applying this operation twice decodes ``stream`` back to the initial state.

    Parameters
    ----------
    stream: :class:`bytes`
        Data to apply XOR on.

    key: :class:`int`
        Key to use. Type ``u8`` (or ``byte``) should be used, in ``[0; 255]`` range.

    Returns
    -------
    :class:`bytes`
        Data after XOR applied.
    """
    return bytes(byte ^ key for byte in stream)