import six


def int_to_base(number, base_str):
    """Converts a number into an array of bytes encoded in the given base."""
    value = []
    base = len(base_str)
    while number > 0:
        value = [base_str[number % base]] + value
        number -= number % base
        number //= base

    # Python 2 / 3 compatibility from hell
    return b''.join(map(six.int2byte, six.iterbytes(value)))