Given an integer value (val) and a numeric base (base),
    encode it into the string of symbols with the given base.
    (with minimum length minlen)

    Returns the (left-padded) re-encoded val as a string.

def encode(val, base, minlen=0):
    """
    Given an integer value (val) and a numeric base (base),
    encode it into the string of symbols with the given base.
    (with minimum length minlen)

    Returns the (left-padded) re-encoded val as a string.
    """

    base, minlen = int(base), int(minlen)
    code_string = get_code_string(base)
    result = ""
    while val > 0:
        result = code_string[val % base] + result
        val //= base
    return code_string[0] * max(minlen - len(result), 0) + result