def baseN_encode(n, alphabet):
    """
    Given an non-negative int, convert it to a string composed of the given
    alphabet mapping
    """
    result = ''
    alphabet = list(alphabet)
    base = len(alphabet)
    current = int(n)
    while 1:
        result = alphabet[current % base] + result
        current = current // base
        if not current: break
    return result