Advertisement
opexxx

b64decode.py

Jun 13th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Simple base64 decoder
  3.  
  4. import sys
  5. import argparse
  6.  
  7. def b64decode(adecode):
  8. """Decode base64 stuff given to us"""
  9. print "Decoding: " + adecode
  10. try:
  11. print adecode.decode("base64")
  12. except Exception, err:
  13. sys.exit("Error: %s" % str(err))   
  14.  
  15. def b64encode(aencode):
  16. """Encode stuff given to us into base64"""
  17. print "Encoding: " + aencode
  18. try:
  19. print aencode.encode("base64")
  20. except Exception, err:
  21. sys.exit("Error: %s" % str(err))
  22.  
  23. def __main__():
  24.  
  25.     parser = argparse.ArgumentParser(description='basic base64 {en,de}coder', usage='%(prog)s -e stuff / -d stuff')
  26.     parser.add_argument('--decode', '-d', dest='decode', help='stuff to decode')
  27.     parser.add_argument('--encode', '-e', dest='encode', help='stuff to encode')
  28.     parser.add_argument('--version', '-v', action='version', version='%(prog)s 0.2')
  29.     args = parser.parse_args()
  30.     adecode = args.decode
  31.     aencode = args.encode
  32.    
  33.     if args.decode:
  34.      b64decode(adecode)
  35.     elif args.encode:
  36.      b64encode(aencode)
  37.     else:
  38.      sys.exit(parser.print_help())
  39.  
  40.  
  41. if __name__ == '__main__':
  42.     __main__()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement