Skip to content

Instantly share code, notes, and snippets.

@moisespsena
Created July 23, 2014 01:40
Show Gist options
  • Save moisespsena/73923f8e0862b2c6db6b to your computer and use it in GitHub Desktop.
Save moisespsena/73923f8e0862b2c6db6b to your computer and use it in GitHub Desktop.
Python Base 36 encode and decode
#!/usr/bin/env python
'''
Python Base 36 encode and decode
'''
__author__ = 'Moises P Sena <moisespsena@gmail.com>'
__version__ = 0.1
CHARS = ''.join(map(str, range(10))) + 'abcdefghijklmnopqrstuvwxyz'
L_CHARS = len(CHARS)
def encode(num):
return (encode((num / L_CHARS) - 1)
if num >= L_CHARS
else '') + CHARS[num % L_CHARS]
if __name__ == '__main__':
print(encode(long(sys.argv[1])))
@rrbarton
Copy link

rrbarton commented May 5, 2021

Can you explain how this is decoding base36 as I only see it encoding it to base36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment