Skip to content

Instantly share code, notes, and snippets.

View nazmulmithu006's full-sized avatar

Nazmul Alam Mithu nazmulmithu006

View GitHub Profile
@nazmulmithu006
nazmulmithu006 / base64.py
Created October 15, 2018 04:56 — forked from jsundram/base64.py
base64 encoding for integers. To make long numbers (i.e. hashes) more readable. Not as cool as RFC 1751, but less code.
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'
TABLE = {c: i for (i, c) in enumerate(ALPHABET)}
def decode(s, b=64):
"""Interpret the input string as a base b number"""
i, multiplier = 0, 1
for c in reversed(s):
i += multiplier * TABLE[c]
multiplier *= b
return i