MCPcopy Create free account
hub / github.com/jimmysong/programmingbitcoin / encode_base58

Function encode_base58

code-ch08/helper.py:28–43  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

26
27
28def encode_base58(s):
29 # determine how many 0 bytes (b'\x00') s starts with
30 count = 0
31 for c in s:
32 if c == 0:
33 count += 1
34 else:
35 break
36 # convert to big endian integer
37 num = int.from_bytes(s, 'big')
38 prefix = '1' * count
39 result = ''
40 while num > 0:
41 num, mod = divmod(num, 58)
42 result = BASE58_ALPHABET[mod] + result
43 return prefix + result
44
45
46def encode_base58_checksum(s):

Callers 1

encode_base58_checksumFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected