Created
July 23, 2014 01:40
-
-
Save moisespsena/73923f8e0862b2c6db6b to your computer and use it in GitHub Desktop.
Python Base 36 encode and decode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you explain how this is decoding base36 as I only see it encoding it to base36