Skip to content

Instantly share code, notes, and snippets.

@macostag
Last active April 12, 2020 23:57
Show Gist options
  • Save macostag/403b18b069e92e1cf84b768c33a72b0d to your computer and use it in GitHub Desktop.
Save macostag/403b18b069e92e1cf84b768c33a72b0d to your computer and use it in GitHub Desktop.
Encoding and decoding Base64 (Nonstandard Bas64 character set)
import base64
chr_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
non_chr_set = "0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz="
encoded = "G6JgP6w="
re_encoded = ""
for en_chr in encoded:
re_encoded += en_chr.replace(en_chr,chr_set[non_chr_set.find(en_chr)])
decoded = base64.b64decode(re_encoded)
print decoded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment