Given a b58check or c32check address,
    return the b58check encoding
19946
def address_as_b58(addr):
    
    if is_c32_address(addr):
        return c32ToB58(addr)

    else:
        if check_address(addr):
            return addr
        else:
            raise ValueError('Address {} is not b58 or c32'.format(addr))
75775
function base32EncodeNextChucks(previous, current, byteIndex, base32) {
    var chunk;
    const offset = byteIndex % 5;
    switch (offset) {
        case 0:
            chunk = (current & 0xF8) >>> 3;
            base32 += base32LookupTable[chunk];
            break;
        case 1:
            chunk = ((previous & 0x07) << 2) | ((current & 0xC0) >>> 6);
            base32 += base32LookupTable[chunk];
            chunk = (current & 0x3E) >>> 1;
            base32 += base32LookupTable[chunk];
            break;
        case 2:
            chunk = ((previous & 0x01) << 4) | ((current & 0xF0) >>> 4);
            base32 += base32LookupTable[chunk];
            break;
        case 3:
            chunk = ((previous & 0x0F) << 1) | ((current & 0x80) >>> 7);
            base32 += base32LookupTable[chunk];
            chunk = (current & 0x7C) >>> 2;
            base32 += base32LookupTable[chunk];
            break;
        case 4:
            chunk = ((previous & 0x03) << 3) | ((current & 0xE0) >>> 5);
            base32 += base32LookupTable[chunk];
            chunk = current & 0x1F;
            base32 += base32LookupTable[chunk];
            break;
    }
    return base32;
}
1071403
def b58decode(v, length=None):
    
    if isinstance(v, bytes):
        v = v.decode()

    for c in v:
        if c not in __b58chars:
            raise ValueError("invalid Base58 string")

    long_value = 0
    for (i, c) in enumerate(v[::-1]):
        long_value += __b58chars.find(c) * (__b58base ** i)

    result = b""
    while long_value >= 256:
        div, mod = divmod(long_value, 256)
        result = struct.pack("B", mod) + result
        long_value = div
    result = struct.pack("B", long_value) + result

    nPad = 0
    for c in v:
        if c == __b58chars[0]:
            nPad += 1
        else:
            break

    result = b"\x00" * nPad + result
    if length is not None and len(result) != length:
        return None

    return result
1188725
def address(self):
        
        if self.isDirect():
            base36 = self._iban[4:]
            asInt = int(base36, 36)
            return to_checksum_address(pad_left_hex(baseN(asInt, 16), 20))

        return ""
1075094
def b58check_unpack(b58_s):
    
    num_leading_zeros = len(re.match(r'^1*', b58_s).group(0))
    # convert from b58 to b16
    hex_s = change_charset(b58_s, B58_KEYSPACE, HEX_KEYSPACE)
    # if an odd number of hex characters are present, add a zero to the front
    if len(hex_s) % 2 == 1:
        hex_s = "0" + hex_s
    # convert from b16 to b2
    bin_s = unhexlify(hex_s)
    # add in the leading zeros
    bin_s = '\x00' * num_leading_zeros + bin_s
    # make sure the newly calculated checksum equals the embedded checksum
    newly_calculated_checksum = bin_checksum(bin_s[:-4])
    embedded_checksum = bin_s[-4:]
    if not (newly_calculated_checksum == embedded_checksum):
        raise ValueError('b58check value has an invalid checksum')
    # return values
    version_byte = bin_s[:1]
    encoded_value = bin_s[1:-4]
    checksum = bin_s[-4:]
    return version_byte, encoded_value, checksum
771621
def b58encode_int(i, default_one=True):
    ''''''
    if not i and default_one:
        return alphabet[0]
    string = ""
    while i:
        i, idx = divmod(i, 58)
        string = alphabet[idx] + string
    return string
412382
def b58check_encode(bin_s, version_byte=0):
    
    # append the version byte to the beginning
    bin_s = chr(int(version_byte)) + bin_s
    # calculate the number of leading zeros
    num_leading_zeros = len(re.match(r'^\x00*', bin_s).group(0))
    # add in the checksum add the end
    bin_s = bin_s + bin_checksum(bin_s)
    # convert from b2 to b16
    hex_s = hexlify(bin_s)
    # convert from b16 to b58
    b58_s = change_charset(hex_s, HEX_KEYSPACE, B58_KEYSPACE)

    return B58_KEYSPACE[0] * num_leading_zeros + b58_s
1099914
def b58encode(b, errors='strict'):
    ""
    len_ = len(b)

    # Convert big-endian bytes to integer
    n = BigInteger.deserialize(BytesIO(b), len_)

    # Divide that integer into base58
    res = []
    while n > 0:
        n, r = divmod (n, 58)
        res.append(b58digits[r])
    res = ''.join(res[::-1])

    # Encode leading zeros as base58 zeros
    pad = 0
    for c in b:
        if c == six.int2byte(0): pad += 1
        else: break
    return (b58digits[0] * pad + res, len_)
1162723
def b58decode_int(v):
    ''''''

    if not isinstance(v, str):
        v = v.decode('ascii')

    decimal = 0
    for char in v:
        decimal = decimal * 58 + alphabet.index(char)
    return decimal
1070442
private static int computeChecksum(byte[] buf, int offset, int length, String channel) {
        Hasher hasher = Hashing.murmur3_32().newHasher();
        hasher.putBytes(buf, offset, length);
        hasher.putUnencodedChars(channel);
        return hasher.hash().asInt() & 0xffff;
    }
284483
def readEncodedU32(self):
        
        self.reset_bits_pending();
        result = self.readUI8();
        if result & 0x80 != 0:
            result = (result & 0x7f) | (self.readUI8() << 7)
            if result & 0x4000 != 0:
                result = (result & 0x3fff) | (self.readUI8() << 14)
                if result & 0x200000 != 0:
                    result = (result & 0x1fffff) | (self.readUI8() << 21)
                    if result & 0x10000000 != 0:
                        result = (result & 0xfffffff) | (self.readUI8() << 28)
        return result
102405
def _verify_encoding(self, enc):
        """"""

        enc = PYTHON_ENCODING_NAMES.get(enc, enc)
        try:
            codecs.getencoder(enc)
            encoding = enc
        except LookupError:
            encoding = None
        return encoding
389166
function getCanonicalAddress(addresses) {
  // We suppose that the addresses are all valid, and therefore use loose regex
  for (var i = 0; i < addresses.length; i++) {
    var addresse = addresses[i];
    if ((/^127(\.\d{1,3}){3}$/.test(addresse.host)) || (/0?:?0?:?0?:?0?:?0?:?0?:0?:1/.test(addresse.host))) {
      addresse.value = 0;
    }
    else if ((net.isIPv6(addresse.host)) && (/^[fF]|[eE]80:.*\:.*\:/.test(addresse.host))) {
      addresse.value = 1;
    }
    else if (/^169\.254\.\d{1,3}\.\d{1,3}$/.test(addresse.host)) {
      addresse.value = 2;
    }
    else if (/^192\.168\.\d{1,3}\.\d{1,3}$/.test(addresse.host)) {
      addresse.value = 3;
    }
    else if (/^172\.(1\d|2\d|30|31)\.\d{1,3}\.\d{1,3}$/.test(addresse.host)) {
      addresse.value = 4;
    }
    else if (/^10(\.\d{1,3}){3}$/.test(addresse.host)) {
      addresse.value = 5;
    }
    else if ((net.isIPv6(addresse.host)) && (/^[fF]|[cCdD].*\:.*\:/.test('addresse.host'))) {
      addresse.value = 6;
    }
    else {
      addresse.value = 7;
    }
  }
  var result = addresses[0];
  var max = addresses[0].value;
  for (var z = 0; z < addresses.length; z++) {
    if (addresses[z].value > max) {
      result = addresses[z];
      max = addresses[z].value;
    }
  }
  return result;
}
300539
def to_base58
      h = to_payload.bth
      hex = h + Bitcoin.calc_checksum(h)
      Base58.encode(hex)
    end
766471
def b58decode_check(v: str) -> bytes:
    ''''''

    result = b58decode(v)
    result, check = result[:-4], result[-4:]
    digest = sha256(sha256(result).digest()).digest()

    if check != digest[:4]:
        raise ValueError("Invalid checksum")

    return result
1056033
def decode(s, checksum=True):
    """"""
    v, prefix = to_long(
        BASE58_BASE, lambda c: BASE58_LOOKUP[c], s.encode("utf8"))

    data = from_long(v, prefix, 256, lambda x: x)

    if checksum:
        data, the_hash = data[:-4], data[-4:]
        if utils.hash256(data)[:4] == the_hash:
            return data
        raise ValueError("hashed base58 has bad checksum %s" % s)

    return data
171086
def genkey(outcompressed=True,prefix='80'):
    '''
    
    '''

    key = prefix + genkeyhex()
    if outcompressed:
        key = key + '01'
    return b58e(key)