#!/usr/bin/python

'''
base64encode.py

Copyright 2006 Andres Riancho

This file is part of w3af, w3af.sourceforge.net .

w3af is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

w3af is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with w3af; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

'''

import base64
import sys
import getopt
try:
    import core.controllers.outputManager as om
except:
    class om:
        class out:
            def information( str ):
                print '\r' + str
            information = staticmethod(information)

def usage():
    om.out.information('w3af - base64 encoder')
    om.out.information('')
    om.out.information('Options:')
    om.out.information('    -h  Print this help message.')
    om.out.information('    -e  String to be encoded.')
    om.out.information('')
    om.out.information('Example: base64encode -e encodeMeNow')
    
def main():
    
    try:
        opts, args = getopt.getopt(sys.argv[1:], "he:", ["help", "encode"])
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)
    encode = None
    for o, a in opts:
        if o in ("-e", "--encode"):
            encode = a
        if o in ("-h", "--help"):
            usage()
            sys.exit()

    if encode is None:
            usage()
            sys.exit()
    else:
        om.out.information( base64.b64encode( encode) )
        
if __name__ == "__main__":
  main()
  
