Skip to content

Instantly share code, notes, and snippets.

@potato4d
Created May 29, 2014 13:56
Show Gist options
  • Save potato4d/c586e19bc63e20c7a299 to your computer and use it in GitHub Desktop.
Save potato4d/c586e19bc63e20c7a299 to your computer and use it in GitHub Desktop.
base64 encoder and decoder for python3.x
#!/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