Skip to content

Instantly share code, notes, and snippets.

@matcool
Last active July 12, 2018 16:10
Show Gist options
  • Save matcool/9ada9eadf42d462c76ffa09b688e3e4f to your computer and use it in GitHub Desktop.
Save matcool/9ada9eadf42d462c76ffa09b688e3e4f to your computer and use it in GitHub Desktop.
really unescessary because of the base64 module but eh
def decode(s):
result = ''
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
for i in range(0,len(s),4):
b = [chars.find(s[j]) for j in range(i,i+4)]
result += chr((b[0] << 2) | (b[1] >> 4))
if (b[2] != 64): result += chr(((b[1] & 15) << 4) | (b[2] >> 2))
if (b[3] != 64): result += chr(((b[2] & 3) << 6) | b[3])
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment