Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cwisbg
- import random as r
- import os
- #___file_name_&_file_path___#
- fileName =("codeTest")
- if os.name == "nt":#Windows
- macOrWin = 1
- elif os.name == "posix":#Mac
- macOrWin = 0
- macPath = (os.path.expanduser("~/Desktop/"))
- winPath = "E:/Rando/scripts/"
- filePath = [macPath, winPath]
- fileType = ".doc",".txt"
- #_____________________
- codeSrc = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .,;:!@$%^&*(){}[]|")
- codeEnc = list(codeSrc)
- r.shuffle(codeEnc)
- codeEnc = "".join(codeEnc)
- def enCode(list):
- encodedStr = ""
- for x in list:
- for a in x:
- if a in codeSrc:
- a = codeEnc[codeSrc.index(a)]
- encodedStr += a
- return encodedStr
- def deCode(list,key):
- decodedStr = ""
- if key == False:
- key = codeEnc
- for x in list:
- for a in x:
- if a in codeEnc:
- a = codeSrc[key.index(a)]
- decodedStr += a
- return decodedStr
- #_____________________
- securityCheck = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]),"r")
- keyCheck = securityCheck.readline()
- keyCheck = keyCheck[:-2]
- getPasword = securityCheck.readline()
- plen = len(getPasword)
- getPasword = getPasword[8:-10]
- if len(keyCheck) == len(codeSrc):
- key = keyCheck
- getPasword = deCode(getPasword, key)
- a = 3
- x = 1
- while x:
- pasword = raw_input("Enter Pasword: ")
- if pasword == getPasword:
- x = 0
- elif a == 0:
- print ("sorry, no more tries")
- quit()
- else:
- print ("not the correct pasword pleas try again \n")
- a -= 1
- fileToDeco = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]),"r").readlines()
- fileDeco = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]),"w")
- decodedStr = deCode(fileToDeco,key)
- cut = len(codeSrc)+plen
- decodedStr = decodedStr[cut:][2:]
- fileDeco.write(decodedStr)
- fileDeco.close()
- else:
- key = []
- keyCheck = []
- pasword = raw_input("Create Pasword: ",)
- codefile = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]), "r").readlines()
- fileEncd = open("{0}{1}{2}".format(filePath[macOrWin],fileName,fileType[1]),"w")
- encodedStr = enCode(codefile)
- fileEncd.write(codeEnc)
- pasword = "\r\npasword:"+pasword+":pasword"
- pasword = enCode(pasword)
- fileEncd.write(pasword)
- fileEncd.write("\r\n")
- fileEncd.write(encodedStr)
- fileEncd.close()
- print ("done")
Advertisement
Add Comment
Please, Sign In to add comment