سورس برنامه رمزنگاری و رمزگشایی فایل به زبان پایتون
امروز سورس برنامه رمزنگاری و رمزگشایی فایل ها رو که به زبان پایتون نوشتم رو در اختیارتون میذارم. امید وارم براتون مفید باشه.
توجه: برای استفاده از سورس باید سه کتابخونه: pyAesCrypt و prettytable و colorama رو نصب کنید.
نحوه نصبشون هم خیلی آسونه فقط کافیه cmd رو بازکنید و با دستور cd به مسیر نصب پایتون برید و با دستور pip instal نصبشون کنید.
مثال:
1pip install colorama
سورس
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344import os import sys import pyAesCrypt from prettytable import PrettyTable from colorama import init, AnsiToWin32, Fore, Back #------------------------------------------------------------------------- init(wrap=False) stream = AnsiToWin32(sys.stderr).stream bufferSize = 64 * 1024 password = ''" #------------------------------------------------------------------------- def clearScreen(): os.system('cls') #------------------------------------------------------------------------- def empty(string) if not string or string.isspace() return True else: return False #------------------------------------------------------------------------- def printEnterAnyKey(): print() changeForeColor(Fore.WHITE) res = input("Do you want to continue? (yes/no) ") if not res == 'yes': os.system("exit") #------------------------------------------------------------------------- def printText(msg): changeForeColor(Fore.WHITE) print(msg) def printError(error): changeForeColor(Fore.RED) if not error: print("An Error Occurred!") else: print(error) def printSucess(msg): changeForeColor(Fore.GREEN) print(msg) #------------------------------------------------------------------------- def getDesktopPath(): return ("C:\\" + os.path.join(os.environ["HOMEPATH"], "Desktop")) #------------------------------------------------------------------------- def changeForeColor(color): print(color, end='', file=stream) #------------------------------------------------------------------------- def saveInDesktop(): changeForeColor(Fore.YELLOW) res = input('Do you want to save key file in desktop? (yes/no) ') if res=='yes': return True else: return False #------------------------------------------------------------------------- def readTxtFile(path): return open(path, "rb").read() #------------------------------------------------------------------------- def encrypt(): clearScreen() filePath = "" source = "" dest = "" global password changeForeColor(Fore.YELLOW) print("Encrypt Files".center(30, "-")) select = 0 while select<1 or select>2: changeForeColor(Fore.LIGHTGREEN_EX) print() print("1- Encrypt File") print("2- Encrypt Folder Content (Files)") print() changeForeColor(Fore.LIGHTBLUE_EX) inp = input("Enter Option Number: ") print() if inp.isdigit(): select = int(inp) if select<0 or select>2: continue if select==1: while not os.path.exists(filePath) or not os.path.isfile(filePath): changeForeColor(Fore.YELLOW) print("Enter a valid file path:") changeForeColor(Fore.WHITE) filePath = input() fileDir, fileName = os.path.split(filePath) source = filePath if fileDir.endswith("/") or fileDir.endswith("\\"): dest = fileDir + fileName + ".aes" else: dest = fileDir + "/" + fileName + ".aes" while empty(password): changeForeColor(Fore.LIGHTBLUE_EX) print() password = input("Please Enter Your Password: ") changeForeColor(Fore.WHITE) try: changeForeColor(Fore.YELLOW) print() print("Please Wait, Encrypting File...") pyAesCrypt.encryptFile(filePath, dest, password, bufferSize) printSucess("File Encrypted Sucessfully.") printError("Deleting {0}...".format(source)) os.remove(source) printSucess("{0} Deleted.".format(source)) print() changeForeColor(Fore.LIGHTGREEN_EX) print("Encrypting Complete.".center(30, "-")) print() except: printError("") printEnterAnyKey() if select==2: while not os.path.exists(filePath) or not os.path.isdir(filePath): changeForeColor(Fore.YELLOW) print() print("Enter a valid directory path:") changeForeColor(Fore.WHITE) filePath = input() table = PrettyTable() table.field_names = ["#", "Name"] counter = 1 list_of_fad = os.listdir(filePath) for item in list_of_fad: current_path = "" if filePath.endswith("/") or filePath.endswith("\\"): current_path = filePath + item else: current_path = filePath + "/" + item if os.path.isfile(current_path): table.add_row([str(counter), os.path.basename(item)]) counter += 1 print(table) print() while empty(password): changeForeColor(Fore.LIGHTBLUE_EX) password = input("Please Enter Your Password: ") changeForeColor(Fore.WHITE) print() for item in os.listdir(filePath): current_path = "" if filePath.endswith("/") or filePath.endswith("\\"): current_path = filePath + item else: current_path = filePath + "/" + item source = current_path if os.path.isfile(source): dest = source + ".aes" try: changeForeColor(Fore.YELLOW) print("Please Wait, Encrypting File...") pyAesCrypt.encryptFile(current_path, dest, password, bufferSize) printSucess("{0} Encrypted Sucessfully.".format(item)) printError("Deleting {0}...".format(item)) os.remove(current_path) printSucess("{0} Deleted.".format(current_path)) print() except: printError("") printEnterAnyKey() print() changeForeColor(Fore.LIGHTGREEN_EX) print("Encrypting Complete.".center(30, "-")) print() #------------------------------------------------------------------------- def decrypt(): clearScreen() filePath = "" source = "" dest = "" global password changeForeColor(Fore.YELLOW) print("Decrypt Files".center(30, "-")) select = 0 while select<1 or select>2: changeForeColor(Fore.LIGHTGREEN_EX) print() print("1- Decrypt File") print("2- Decrypt Folder Content (Files)") print() changeForeColor(Fore.LIGHTBLUE_EX) inp = input("Enter Option Number: ") print() if inp.isdigit(): select = int(inp) if select<0 or select>2: continue if select==1: while not os.path.exists(filePath) or not os.path.isfile(filePath) or not filePath.endswith(".aes"): changeForeColor(Fore.YELLOW) print("Enter a valid file path:") changeForeColor(Fore.WHITE) filePath = input() fileDir, fileName = os.path.split(filePath) source = filePath if fileDir.endswith("/") or fileDir.endswith("\\"): dest = fileDir + fileName else: dest = fileDir + "/" + fileName if source.endswith(".aes"): dest = source[0:-4] while empty(password): changeForeColor(Fore.LIGHTBLUE_EX) print() password = input("Please Enter Your Password: ") changeForeColor(Fore.WHITE) try: changeForeColor(Fore.YELLOW) print() print("Please Wait, Decrypting File...") pyAesCrypt.decryptFile(filePath, dest, password, bufferSize) printSucess("File Decrypted Sucessfully.") printError("Deleting {0}...".format(source)) os.remove(source) printSucess("{0} Deleted.".format(source)) print() changeForeColor(Fore.LIGHTGREEN_EX) print("Decrypting Complete.".center(30, "-")) print() except: printError("") printEnterAnyKey() if select==2: while not os.path.exists(filePath): changeForeColor(Fore.YELLOW) print() print("Enter a valid directory path:") changeForeColor(Fore.WHITE) filePath = input() print() table = PrettyTable() table.field_names = ["#", "Name"] counter = 1 aes_counter = 0 list_of_fad = os.listdir(filePath) for item in list_of_fad: current_path = "" if filePath.endswith("/") or filePath.endswith("\\"): current_path = filePath + item else: current_path = filePath + "/" + item if os.path.isfile(current_path) and filePath.endswith(".aes"): table.add_row([str(counter), os.path.basename(item)]) counter += 1 aes_counter += 1 print(table) print() if aes_counter==0: print() printError("Files Not Found...") return while empty(password): changeForeColor(Fore.LIGHTBLUE_EX) password = input("Please Enter Your Password: ") changeForeColor(Fore.WHITE) print() for item in os.listdir(filePath): current_path = "" if filePath.endswith("/") or filePath.endswith("\\"): current_path = filePath + item else: current_path = filePath + "/" + item source = current_path if os.path.isfile(source) and filePath.endswith(".aes"): dest = source[0:-4] try: changeForeColor(Fore.YELLOW) print("Please Wait, Decrypting File...") pyAesCrypt.decryptFile(current_path, dest, password, bufferSize) printSucess("{0} Decrypted Sucessfully.".format(item)) printError("Deleting {0}...".format(item)) os.remove(current_path) printSucess("{0} Deleted.".format(current_path)) print() except: printError("") printEnterAnyKey() print() changeForeColor(Fore.LIGHTGREEN_EX) print("Decrypting Complete.".center(30, "-")) print() #------------------------------------------------------------------------- def aboutMe(): clearScreen() changeForeColor(Fore.YELLOW) print("About Me".center(30, "-")) changeForeColor(Fore.CYAN) print("Programmer: Javad Moradkhah") changeForeColor(Fore.LIGHTGREEN_EX) print("Date: 9 June 2020 | 1399/03/20") print("".center(30, "-")) #------------------------------------------------------------------------- def callFun(n): if n==1: encrypt() elif n==2: decrypt() elif n==3: aboutMe() elif n==4: os.system("exit") #------------------------------------------------------------------------- select = 0 while select<1 or select>4: os.system('cls') print(Fore.LIGHTRED_EX + 'Welcome To LFF (Lock Ficking Files)', file=stream) print() print(Fore.LIGHTGREEN_EX + '1- Encrypt Files', file=stream) print(Fore.LIGHTGREEN_EX + '2- Decrypt Files', file=stream) print(Fore.LIGHTGREEN_EX + '3- About Me', file=stream) print(Fore.LIGHTGREEN_EX + '4- Exit', file=stream) print() changeForeColor(Fore.LIGHTBLUE_EX) inp = input("Enter Option Number: ") if inp.isdigit() and (select>=1 or select<=4): select = int(inp) callFun(select)