Created
May 29, 2014 13:56
-
-
Save potato4d/c586e19bc63e20c7a299 to your computer and use it in GitHub Desktop.
base64 encoder and decoder for python3.x
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/local/bin/python | |
#coding:utf-8 | |
import sys | |
import base64 | |
def s2b64_encode(file): | |
#bytes -> base64 | |
#in filename(string) | |
#out bytes(base64) | |
return base64.b64encode(open(file, 'rb').read()) | |
def s2b64_decode(dbytes): | |
#base64 -> bytes -> string | |
#in bytes | |
#out string | |
return bytes.decode(base64.b64decode(dbytes)) | |
if __name__ == '__main__': | |
arg = sys.argv | |
base = s2b64_encode(arg[1]) | |
print(base) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment