Skip to content

Instantly share code, notes, and snippets.

@n8foo
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8foo/8894702 to your computer and use it in GitHub Desktop.
Save n8foo/8894702 to your computer and use it in GitHub Desktop.
alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
base = len(alphabet)
def b58enc(div, s=''):
if div >= base:
div, mod = divmod(div, base)
return b58enc(div, alphabet[mod] + s)
return alphabet[div] + s
def b58dec(s):
return sum(alphabet.index(c) * pow(base, i) for i, c in enumerate(reversed(s)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment