Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
Last active January 4, 2016 04:19
Show Gist options
  • Select an option

  • Save ralphtheninja/8568026 to your computer and use it in GitHub Desktop.

Select an option

Save ralphtheninja/8568026 to your computer and use it in GitHub Desktop.
Base58.py checking decode of '1' and '11' etc
from hashlib import sha256
digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
def decode_base58(bc, length):
n = 0
for char in bc:
n = n * 58 + digits58.index(char)
return n.to_bytes(length, 'big')
if __name__ == '__main__':
print(decode_base58('1', 1))
print(decode_base58('11', 2))
print(decode_base58('111', 3))
$ python3.3 base58.py
b'\x00'
b'\x00\x00'
b'\x00\x00\x00'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment