Skip to content

Instantly share code, notes, and snippets.

@munhitsu
Last active December 14, 2015 16:59
Show Gist options
  • Save munhitsu/5118993 to your computer and use it in GitHub Desktop.
Save munhitsu/5118993 to your computer and use it in GitHub Desktop.
slightly crazy universal base encoder (number to alphabet)
BASE_ALPHABET = "123456789abcdefghijkmnopqrstuvwxyz"
def encode_base_x(n):
base = len(BASE_ALPHABET)
def chars(num):
while num >= base:
num, mod = divmod(num, base)
yield BASE_ALPHABET[mod]
yield BASE_ALPHABET[num]
return "".join(chars(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment