def base_encode(v, base):
 if (base == 58):
  chars = __b58chars
 elif (base == 43):
  chars = __b43chars
 long_value = 0L
 for (i, c) in enumerate(v[::(-1)]):
  long_value += ((256 ** i) * ord(c))
 result = ''
 while (long_value >= base):
  (div, mod) = divmod(long_value, base)
  result = (chars[mod] + result)
  long_value = div
 result = (chars[long_value] + result)
 nPad = 0
 for c in v:
  if (c == '\x00'):
   nPad += 1
  else:
   break
 return ((chars[0] * nPad) + result)

def base_encode ( v , base ) : if ( base == 58 ) : chars = __b58chars elif ( base == 43 ) : chars = __b43chars long_value = 0 L for ( i , c ) in enumerate ( v [ : : ( - 1 ) ] ) : long_value += ( ( 256 ** i ) * ord ( c ) ) result = '' while ( long_value >= base ) : ( div , mod ) = divmod ( long_value , base ) result = ( chars [ mod ] + result ) long_value = div result = ( chars [ long_value ] + result ) nPad = 0 for c in v : if ( c == '\x00' ) : nPad += 1 else : break return ( ( chars [ 0 ] * nPad ) + result )
encode v .