MCPcopy Index your code
hub / github.com/jimmysong/programmingbitcoin / encode_base58

Function encode_base58

code-ch13/helper.py:34–49  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

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

Callers 1

encode_base58_checksumFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected