Advertisement
eudemonics

ENCODELIST.PY - required for EMAIL2FILE.PY v1.4

Apr 18th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import base64, os, sys, re
  3.  
  4. global encfile
  5.  
  6. print('''
  7. ###############################################
  8. ###############################################
  9. ############# #  # #  # #  # #  # #############
  10. #####                                     #####
  11. #####   ENCODELIST.PY FOR EMAIL2FILE.PY   #####
  12. #####                                     #####
  13. #######           VERSION 0.1           #######
  14. #########           by: vvn           #########
  15. ###########                         ###########
  16. ############# #  # #  # #  # #  # #############
  17. ###############################################
  18. ############# #  # #  # #  # #  # #############
  19. ###############################################
  20. ############# #  # #  # #  # #  # #############
  21. #####                                     #####
  22. #####            RELEASE DATE:            #####
  23. #####           APRIL 09, 2015            #####
  24. #####                                     #####
  25. ############# #  # #  # #  # #  # #############
  26. ###############################################
  27. ''')
  28.  
  29. def encode_pass(fn, newfile):
  30.  
  31.    while not os.path.exists(fn):
  32.       fn = raw_input("invalid path. please check file name and enter again --> ")
  33.  
  34.    pf = open(fn, "r+w")
  35.    bf = open(newfile, "wb+")
  36.  
  37.    for line in pf.readlines():
  38.       enctxt = base64.b64encode(line)
  39.       bf.write(enctxt)
  40.       bf.write("\n")
  41.  
  42.    print("base64-encoded lines written to %s") % newfile
  43.    bf.close()
  44.    pf.close()
  45.  
  46. def decode_pass(fn, newfile):
  47.    
  48.    while not os.path.exists(fn):
  49.       fn = raw_input("invalid path. please check file name and enter again --> ")
  50.  
  51.    encfile = open(fn, "r+")
  52.    decfile = open(newfile, "wb+")
  53.    for line in encfile.readlines():
  54.       dectext = base64.b64decode(line)
  55.       decfile.write(dectext)
  56.       decfile.write("\n")
  57.    decfile.close()
  58.    
  59.    print("base-64 decoded lines written to %s") % newfile
  60.  
  61. def gen_list():
  62.    selection = raw_input("enter 1 to encode or 2 to decode a password list --> ")
  63.    while not re.search(r'^[12]$', selection):
  64.       selection = raw_input("invalid selection. enter 1 to encode or 2 to decode --> ")
  65.    
  66.    if selection == '1':
  67.       origfile = raw_input("please copy password list file to script directory and enter filename --> ")
  68.       while not os.path.exists(origfile):
  69.          origfile = raw_input("cannot find the file specified. please check path and enter correct filename --> ")
  70.       encfile = raw_input("please enter filename to save new encoded list --> ")
  71.       while not re.match(r'^[\w\-. ]+$', encfile):
  72.          encfile = raw_input("invalid format. please enter a valid filename --> ")
  73.       print("encoding each entry in password file..")
  74.       encode_pass(origfile, encfile)
  75.       delsel = raw_input("delete the original unencoded password file? Y/N --> ")
  76.       while not re.match(r'^[nNyY]$', delsel):
  77.          delsel = raw_input("invalid selection. enter Y to delete or N to keep original unencoded file --> ")
  78.       if delsel.lower() == 'y':
  79.          try:
  80.             os.remove(origfile)
  81.             if os.path.isfile(origfile):
  82.                os.unlink(origfile)
  83.             print('%s deleted successfully.' % origfile)
  84.          except OSError, e:
  85.             print ("Error: %s - %s." % (e.filename,e.strerror))
  86.       else:
  87.          if os.path.isfile(origfile):
  88.             print('%s contains sensitive data. please delete it manually ASAP.' % origfile)
  89.    else:
  90.       encfile = raw_input("please enter filename of encoded password list --> ")
  91.       while not os.path.exists(encfile):
  92.          encfile = raw_input("cannot find the file specified. please check path and enter correct filename --> ")
  93.       newfile = raw_input("please enter filename to save new decoded entries --> ")
  94.       while not re.match(r'^[\w\-. ]+$', newfile):
  95.          newfile = raw_input("invalid format. please enter a valid filename --> ")
  96.       print("decoding each entry in password file %s..") % encfile
  97.       encode_pass(encfile, newfile)
  98.    def exitmenu():
  99.       exitsel = raw_input("enter 1 to run script again. enter 2 to run email2file script. enter 3 to print encoded/decoded data. to exit, enter 4 --> ")
  100.  
  101.       while not re.search(r'^[1-4]$', exitsel):
  102.          exitsel = raw_input("invalid entry. enter 1 to run script again, 2 to run email2file script, 3 to show encoded/decoded data, or 4 to exit --> ")
  103.    
  104.       if exitsel == '1':
  105.          gen_list()
  106.          exitmenu()
  107.    
  108.       elif exitsel == '2':
  109.          os.system('chmod +x email2file.py')
  110.          os.system('./email2file.py')
  111.    
  112.       elif exitsel == '3':
  113.          ef = open(encfile, "r+")
  114.          for n in ef.readlines():
  115.             print("encoded: %s" % n)
  116.             dectext = base64.b64decode(n)
  117.             print("decoded: %s" % dectext)
  118.          ef.close()
  119.          exitmenu()
  120.  
  121.       else:
  122.          print("goodbye!")
  123.    exitmenu()
  124.    
  125. gen_list()
  126.  
  127. print("exiting program..")
  128.    
  129. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement