encode v, which is a string of bytes, to base58.
(v)
| 24 | b58chars = __b58chars |
| 25 | |
| 26 | def 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 | |
| 53 | def b58decode(v, length = None): |
| 54 | """ decode v into a string of len bytes |
no test coverage detected