cwisbg

scrambler_v4

May 18th, 2012
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.52 KB | None | 0 0
  1. #cwisbg
  2. import random as r
  3. import os
  4. #___file_name_&_file_path___#  
  5. fileName =("codeTest")
  6. if os.name == "nt":#Windows
  7.     macOrWin = 1
  8. elif os.name == "posix":#Mac
  9.    macOrWin = 0
  10. macPath = (os.path.expanduser("~/Desktop/"))
  11. winPath = "E:/Rando/scripts/"
  12. filePath = [macPath, winPath]
  13. fileType = ".doc",".txt"
  14. #_____________________
  15. codeSrc = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .,;:!@$%^&*(){}[]|")
  16. codeEnc = list(codeSrc)
  17. r.shuffle(codeEnc)
  18. codeEnc = "".join(codeEnc)
  19. def enCode(list):
  20.     encodedStr = ""
  21.     for x in list:
  22.         for a in x:
  23.             if a in codeSrc:
  24.                 a = codeEnc[codeSrc.index(a)]
  25.             encodedStr += a
  26.     return encodedStr
  27. def deCode(list,key):
  28.     decodedStr = ""
  29.     if key == False:
  30.         key = codeEnc      
  31.     for x in list:
  32.         for a in x:
  33.             if a in codeEnc:
  34.                 a = codeSrc[key.index(a)]
  35.             decodedStr += a
  36.     return decodedStr  
  37. #_____________________
  38. securityCheck = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]),"r")
  39. keyCheck = securityCheck.readline()
  40. keyCheck = keyCheck[:-2]
  41. getPasword = securityCheck.readline()
  42. plen = len(getPasword)
  43. getPasword = getPasword[8:-10]
  44. if len(keyCheck) == len(codeSrc):
  45.     key = keyCheck
  46.     getPasword = deCode(getPasword, key)
  47.     a = 3
  48.     x = 1
  49.     while x:
  50.         pasword = raw_input("Enter Pasword:   ")
  51.         if pasword == getPasword:
  52.             x = 0
  53.         elif a == 0:
  54.             print ("sorry, no more tries")
  55.             quit()
  56.         else:
  57.             print ("not the correct pasword pleas try again \n")
  58.             a -= 1
  59.     fileToDeco = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]),"r").readlines()
  60.     fileDeco = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]),"w")
  61.     decodedStr = deCode(fileToDeco,key)
  62.     cut = len(codeSrc)+plen
  63.     decodedStr = decodedStr[cut:][2:]
  64.     fileDeco.write(decodedStr)    
  65.     fileDeco.close()
  66. else:
  67.     key = []
  68.     keyCheck = []
  69.     pasword = raw_input("Create Pasword:   ",)
  70.     codefile = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]), "r").readlines()
  71.     fileEncd = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]),"w")
  72.     encodedStr = enCode(codefile)
  73.     fileEncd.write(codeEnc)
  74.     pasword = "\r\npasword:"+pasword+":pasword"
  75.     pasword = enCode(pasword)
  76.     fileEncd.write(pasword)
  77.     fileEncd.write("\r\n")
  78.     fileEncd.write(encodedStr)
  79.     fileEncd.close()  
  80. print ("done")
Advertisement
Add Comment
Please, Sign In to add comment