def pad(data, block_size):
    """ Pads data to a multiple of the block size in a reversible way, by adding n bytes with value n to the data, where
    n is the number of bytes needed to reach a multiple of the block size.

    Args:
        data: The data to pad to a multiple of the block size. Must be a `bytearray`.
        block_size (int): The desired block size. Must be between 1 and 255 (inclusive).
    """
    assert 1 <= block_size <= 255
    n = block_size - len(data) % block_size
    data.extend(bytes([n] * n))
