MCPcopy Create free account
hub / github.com/ElementsProject/elements / b58encode

Function b58encode

contrib/testgen/base58.py:26–51  ·  view source on GitHub ↗

encode v, which is a string of bytes, to base58.

(v)

Source from the content-addressed store, hash-verified

24b58chars = __b58chars
25
26def b58encode(v):
27 """ encode v, which is a string of bytes, to base58.
28 """
29 long_value = 0
30 for (i, c) in enumerate(v[::-1]):
31 if isinstance(c, str):
32 c = ord(c)
33 long_value += (256**i) * c
34
35 result = ''
36 while long_value >= __b58base:
37 div, mod = divmod(long_value, __b58base)
38 result = __b58chars[mod] + result
39 long_value = div
40 result = __b58chars[long_value] + result
41
42 # Bitcoin does a little leading-zero-compression:
43 # leading 0-bytes in the input become leading-1s
44 nPad = 0
45 for c in v:
46 if c == 0:
47 nPad += 1
48 else:
49 break
50
51 return (__b58chars[0]*nPad) + result
52
53def b58decode(v, length = None):
54 """ decode v into a string of len bytes

Callers 2

b58encode_chkFunction · 0.85
base58.pyFile · 0.85

Calls 2

ordFunction · 0.85
enumerateFunction · 0.50

Tested by

no test coverage detected