├── requirements.txt ├── README.md ├── .github └── workflows │ └── python-app.yml └── a10cipher.py /requirements.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # please note that this is one of the first python code that I have ever written. yes it is potato, but it works. 2 | 3 | 4 | # A10_cipher 5 | I MANAGED TO **profanity** FINALLY DECRYPT THIS **profanity** 6 | ```ruby 7 | options: 8 | Removed args, just fire main.py, or exe file. 9 | ``` 10 | well... this was a meme alphabet and cipher that mistakenly created because of some small **profanity** in hill 2x2 matrix decryption, and every encrypted text was decrypted to AAAAAAA. 11 | 12 | every encrypted single message is thrown into message.txt with same folder to wherever you downloaded the .exe. 13 | 14 | I implemented a morse alphabet, that is translated to A10 cipher. For example: 15 | "A" is equal to: Aa0AAA 16 | "E" is equal to: A10AA0A0AAAAAAAAA 17 | Alphabet only supports english language for now. There is a testfolder filled with Silent Planet lyrics. 18 | -------------------------------------------------------------------------------- /.github/workflows/python-app.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Python application 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | build: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Set up Python 3.10 23 | uses: actions/setup-python@v3 24 | with: 25 | python-version: "3.10" 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install flake8 pytest 30 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 31 | - name: Lint with flake8 32 | run: | 33 | # stop the build if there are Python syntax errors or undefined names 34 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 35 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 36 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 37 | - name: Test with pytest 38 | run: | 39 | pytest 40 | -------------------------------------------------------------------------------- /a10cipher.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import json 3 | import os 4 | import sys 5 | import tkinter as tk 6 | from os.path import isfile 7 | from tkinter import filedialog 8 | import portalocker 9 | import click 10 | class Encryptor(): 11 | def __init__(self): 12 | self.AAAAA_code_DICT_lower = { 13 | 'a': 'Aa0AAA', 'b': 'AA0A0A0A0A', 14 | 'c': 'AAA0A0AAA0A', 'd': 'AAA0A0A', 'e': 'A10AA0A0AAA', 15 | 'f': 'A0A0AAA0A', 'g': 'AAA0AAA0A', 'h': 'Aa10A0A0A', 16 | 'i': 'AA0A', 'j': 'aA0AAA0AAA0AAA', 'k': 'AAA0A0AAA', 17 | 'l': 'A0AAA0A0A', 'm': 'AAA0AAA', 'n': 'AAA0AAAA', 18 | 'o': 'AAA0AAA0AAA', 'p': 'A0AAA0AAA0A', 'q': 'AAA0AAA0A0AAA', 19 | 'r': 'A0AAA0A', 's': 'A0A0A', 't': 'AAA', 20 | 'u': 'A0A0AAA', 'v': 'A0A0A0AAA', 'w': 'A0AAA0AAA', 21 | 'x': 'AA0AA0A0AAA', 'y': 'AAAa0A0AAA0A0AA', 'z': 'AAA0AAA0AAAA0A', 22 | '1': 'A0AAA0AAA0AAA0AAA', '2': 'A0A0AAA0AAA0AAA', '3': 'A0A0A0AAA0AAA', 23 | '4': 'A0A0A0A0AAA', '5': 'A0A0A0A0A', '6': 'AAA0A0A0A0A', 24 | '7': 'AAA0AAA0A0A0A', '8': 'AAA0AAA0AAA0A0A', '9': 'AAA0AAA0AAA0AAA0A', 25 | '0': 'AAA0AAA0AAA0AAA0AAA', ',': 'AAA0AAA0A0A0AAA0AAA', '.': 'A0AA0aA0A0AAA0A0AAA', 26 | '?': 'A0A0AAA0AAA0A0A', '/': 'AAA0A0A0AAA0A', '-': 'AAA0A0A0A0A0AAA', 27 | "'": 'A0AAA0AAA0AAA0AAA0A', ":": "AAA0AAA0AAA0A0A0A", 28 | '(': '-.--.', ')': '0AAaAa0A0AAA0AAA0A0AAA', 29 | ";": "0A0AAA0AAaAa0A0AAA0AAA", 30 | "!": "0AA0A0AaaAA0A0AAA0AAA", "[": "AAA0aA0AAA0A0A0AAA", "]": "AAA0AAA0A0A", "&": "A0AAA0A0A0A", 31 | "_": "AAA0A0A0A0AAA", "=": "AAAAAAA", '"': "A0AAA0AAA0AAA0AAA0A0A", '{': "AAA0A0A0A0A0A", 32 | '\\': "AAA0A0A0A0A0AAA", '}': "AAA0A0A0A0A0A0A", '@': "A0AAA0A0A0A0A0A0A0A", '#': "A0AAA0A0A0A0A0A0A0A0A", 33 | '$': "A0AAA0A0A0A0A0A0A0A0A0A", '%': "A0AAA0A0A0aaA0A", '^': "A0AAA0A0A0A0A0A0A0A0A0A0A0A", 34 | '&': "A0AaaaAa0A0A0A", '*': "A0AAA0A0A0A0A0aaaaA0A0A0A0A0A0A", '+': "A0AAAaaaAAaa0A0A0A0A0A0A", 35 | '~': "A0AAaaaAA0A0A0A0A0A", '`': "A0AAA0A0AaaAa", '<': "AAA0A0A0aA0A0A0A0A0A0a", 36 | "â": "A0a0a0AA", "€": "aaaaa00" 37 | } 38 | self.AAAAA_code_DICT_upper = { 39 | 'A': 'A0AAA', 'B': 'AAA0A0A0A0', 40 | 'C': '0AAA0A0AAA0A', 'D': '0AAA0A0A', 'E': '0A', 41 | 'F': '0A0A0AAA0A', 'G': '0AAA0AAA0A', 'H': '0A0A0A0A', 42 | 'I': '0A0A', 'J': '0A0AAA0AAaA0AAA', 'K': '0AAA0A0AAA', 43 | 'L': '0A0AAA0A0A', 'M': '0AAA0AAA', 'N': '0AAA0A', 44 | 'O': '0AAA0AAA0AAA', 'P': '0aA0AAA0AAA0A', 'Q': '0AAA0AAA0A0AAA', 45 | 'R': '0A0AAA0A', 'S': '0A0A0A', 'T': '0AAA', 46 | 'U': '0A0A0AAA', 'V': '0A0A0A0AAA', 'W': '0A0AAA0AAA', 47 | 'X': '0AAA0A0A0AAA', 'Y': '0AAA0A0AAA0AAA', 'Z': '0AAA0AAA0A0A', 48 | '1': '0A0AAaA0AAA0AAA0AAA', '2': '0A0aA0AAA0AAA0AAA', '3': '0A0A0A0AAA0AAA', 49 | '4': '0A0A0A0A0AAA', '5': '0A0A0A0A0A', '6': '0AAA0A0A0A0A', 50 | '7': '0AAA0AAA0A0A0A', '8': '0AAA0AAA0AAA0A0A', '9': '0AAA0AAA0AAA0AAA0A', 51 | '0': '0AAA0AAA0AAA0AAA0AAA', ',': '0AAA0AAA0A0A0AAA0AAA', '.': '0A0AAA0A0AAA0A0AAA', 52 | '?': '0A0aA0AAA0AAA0A0A', '/': '0AAA0A0A0AAA0A', '-': '0AAA0A0A0A0A0AAA', 53 | '(': '-.--.', ')': '0AAA0aA0AAA0AAA0Aa0AAA', ";": "a0A0AAA0aAAA0A0AAA0AAA", 54 | ":": "AAA0AAA0AAA0A0A0A", "!": "0AAA0A0AAA0A0AAA0AAA", 55 | "[": "AAA0A0AAA0A0A0AAA", "]": "AAA0AAA0A0A", "&": "A0AAA0A0A0A" 56 | } 57 | self.lowerinverted = {v: k for k, v in self.AAAAA_code_DICT_lower.items()} 58 | self.upperinverted = {v: k for k, v in self.AAAAA_code_DICT_upper.items()} 59 | 60 | def decrypt_msg(self, msg): 61 | lowerdict = self.lowerinverted 62 | upperdict = self.upperinverted 63 | s = "" 64 | deciphered = "" 65 | y = msg.split(" ") 66 | print(y) 67 | for s in y: 68 | if "\n" in s: 69 | deciphered += "\n" 70 | placeholder = s.replace("\n", "") 71 | s = placeholder 72 | if "NEW_WORD" in s: 73 | deciphered += " " 74 | placeholder = s.replace("NEW_WORD", "") 75 | s = placeholder 76 | if s in lowerdict.keys(): 77 | deciphered += lowerdict[s] 78 | elif s in upperdict.keys(): 79 | deciphered += upperdict[s] 80 | if s == "|": 81 | deciphered += "|" 82 | if y.index(s) == len(y) - 1: 83 | deciphered += " " 84 | s = "" 85 | print(deciphered) 86 | return deciphered 87 | 88 | def encrypt_msg(self, msg): 89 | lowerdict = self.AAAAA_code_DICT_lower 90 | upperdict = self.AAAAA_code_DICT_upper 91 | s = "" 92 | ciphered = "" 93 | y = msg.split(" ") 94 | print(y) 95 | for letter in msg: 96 | # Side note, ; is equal to .--.-- This is not a valid morse code, but it is valid on AAAArse code alphabet. 97 | # Check line 54. 98 | # [ is equal to AAA A AAA A A AAA. -.-..- 99 | # ] is equal to AAA AAA A A. --.. It might be valid for something on morse alphabet but doot it. 100 | letter_check = letter.isupper() 101 | if (letter != " ") and (letter_check == True) and (letter != "\n") and (letter != "|"): 102 | ciphered += upperdict[letter] + " " 103 | elif (letter != " ") and (letter_check == False) and (letter != "\n") and (letter != "|"): 104 | ciphered += lowerdict[letter] + " " 105 | elif letter == "\n": 106 | ciphered += "\n" 107 | elif letter == "|": 108 | ciphered += "|" 109 | else: 110 | ciphered += "00" 111 | print(ciphered) 112 | return ciphered 113 | 114 | def encrypt_file(self, file_name, path): 115 | lowerdict = self.AAAAA_code_DICT_lower 116 | upperdict = self.AAAAA_code_DICT_upper 117 | ciphered = "" 118 | y = file_name.split(" ") 119 | for words in y: 120 | ciphered += "NEW_WORD" 121 | for letter in words: 122 | # Side note, ; is equal to .--.-- This is not a valid morse code, but it is valid on AAAArse code alphabet. 123 | # Check line 54. 124 | # [ is equal to AAA A AAA A A AAA. -.-..- 125 | # ] is equal to AAA AAA A A. --.. It might be valid for something on morse alphabet but doot it. 126 | letter_check = letter.isupper() 127 | if (letter != " ") and (letter_check == True) and (letter != "\n") and (letter != "|"): 128 | ciphered += upperdict[letter] + " " 129 | elif (letter != " ") and (letter_check == False) and (letter != "\n") and (letter != "|"): 130 | ciphered += lowerdict[letter] + " " 131 | elif letter == "\n": 132 | ciphered += "\n" 133 | elif letter == "|": 134 | ciphered += "|" 135 | else: 136 | ciphered += "" 137 | with open(path, "w") as f: 138 | f.write(ciphered) 139 | 140 | def decrypt_file(self, file_data, path): 141 | lowerdict = self.lowerinverted 142 | upperdict = self.upperinverted 143 | s = "" 144 | deciphered = "" 145 | y = file_data.split(" ") 146 | for s in y: 147 | if "\n" in s: 148 | deciphered += "\n" 149 | placeholder = s.replace("\n", "") 150 | s = placeholder 151 | if "NEW_WORD" in s: 152 | deciphered += " " 153 | placeholder = s.replace("NEW_WORD", "") 154 | s = placeholder 155 | else: 156 | pass 157 | if s in lowerdict.keys(): 158 | deciphered += lowerdict[s] 159 | elif s in upperdict.keys(): 160 | deciphered += upperdict[s] 161 | if s == "|": 162 | deciphered += "|" 163 | with open(path, "w") as f: 164 | f.write(deciphered) 165 | print("Decryption is done!") 166 | return deciphered 167 | 168 | 169 | def change_file_extension(file, new_extension): 170 | # Get old extension of file for replacing later 171 | old_extension = file.split(".")[-1] 172 | # Get file name without extension 173 | file_name = file.split(".")[0] 174 | # Replace .AAAA as a new extension 175 | new_file_name = file_name + "." + new_extension 176 | # Overwrite old file with new file 177 | os.rename(file, new_file_name) 178 | z = file.split(old_extension) 179 | # Add .AAAAA to the end of the z 180 | new_file_path = z[0] + new_extension 181 | # Store old file name without extension and old extension in a new dictionary 182 | file_dict = {new_file_path: old_extension} 183 | exportlist = [] 184 | exportlist.append(file_dict) 185 | # Return new file name 186 | return new_file_name, exportlist 187 | 188 | 189 | def encrypt_txt_folder(dir): 190 | # Iterate through every file in the directory 191 | for file in os.listdir(dir): 192 | # If the file is a .txt file 193 | if file.endswith(".txt"): 194 | # Get path of file 195 | path = os.path.join(dir, file) 196 | # Open the file in read mode 197 | with open(path, "r") as f: 198 | # Read the contents of the file 199 | data = f.read() 200 | # Encrypt the contents of the file 201 | # Get path of the file 202 | y = Encryptor() 203 | y.encrypt_file(data, path) 204 | 205 | def encrypt_txt_files(file): 206 | encryptor = Encryptor() 207 | with open(file, "r") as f: 208 | file_data = f.read() 209 | encryptor.encrypt_file(file_data, file) 210 | 211 | 212 | def encrypt_messages(message): 213 | encryptor = Encryptor() 214 | ciphered = encryptor.encrypt_msg(message) 215 | with open("message.txt", "w") as f: 216 | f.write(ciphered) 217 | return ciphered 218 | 219 | 220 | def decrypt_txt_folder(dir): 221 | if os.path.isdir(folder): 222 | # Find files in subfolders 223 | for file in os.listdir(folder): 224 | if file.endswith(".txt"): 225 | print("Now encrypting {}".format(file)) 226 | # Encrypt files 227 | encryptor = Encryptor() 228 | # Get path of the file 229 | path = os.path.join(folder, file) 230 | with open(path, "r") as f: 231 | file_data = f.read() 232 | encryptor.decrypt_file(file_data, path) 233 | 234 | 235 | def decrypt_messages(message): 236 | encryptor = Encryptor() 237 | deciphered = encryptor.decrypt_msg(message) 238 | print(deciphered) 239 | with open("message.txt", "w") as f: 240 | f.write(deciphered) 241 | return deciphered 242 | 243 | 244 | def decrypt_txt_file(file): 245 | encryptor = Encryptor() 246 | with open(file, "r") as f: 247 | file_data = f.read() 248 | encryptor.decrypt_file(file_data, file) 249 | 250 | 251 | class FileOfType: 252 | def __init__(self, type): 253 | self.type = type 254 | assert type in ['dir', 'file'] 255 | 256 | def __call__(self, path): 257 | if self.type == 'dir': 258 | if not os.path.isdir(path): 259 | raise argparse.ArgumentTypeError(f"{path} is not a directory") 260 | elif self.type == 'file': 261 | if not os.path.isfile(path): 262 | raise argparse.ArgumentTypeError(f"{path} is not a regular file") 263 | elif os.path.islink(path): 264 | raise argparse.ArgumentTypeError(f"{path} is a symbolic link") 265 | return path 266 | 267 | 268 | if __name__ == "__main__": 269 | parser = argparse.ArgumentParser(description="Change every file extension to .AAAAA in folder") 270 | parser.add_argument("-dir", "--directory", type=FileOfType("dir")) 271 | parser.add_argument("-ge", "-getextension", action="store_true", 272 | help="Gets extension of files in folders to decrypt in the future") 273 | parser.add_argument("-g", "--generate-key", dest="generate_key", action="store_true", 274 | help="Whether to generate a new key or use existing") 275 | parser.add_argument("-e", "--encrypt", action="store_true", help="Encrypts every txt file with AAAA alphabet") 276 | parser.add_argument("-d", "--decrypt", action="store_true", help="Decrypts every txt file with AAAA alphabet") 277 | parser.add_argument("-f", "--file", type=FileOfType("file")) 278 | args = parser.parse_args() 279 | if len(sys.argv) < 2: 280 | flag = True 281 | while flag == True: 282 | print("Please enter a command") 283 | print("1. Encrypt") 284 | print("2. Decrypt") 285 | print("3. Exit") 286 | choice = input() 287 | if choice == "1": 288 | print("Please choose if you want to encrypt a file or a folder") 289 | print("1. File") 290 | print("2. Folder") 291 | print("3. Single Message") 292 | choice = input() 293 | if choice == "1": 294 | root = tk.Tk() 295 | root.withdraw() 296 | root.title("Please choose a file") 297 | file_path = filedialog.askopenfilename() 298 | print("Encrypting file {}".format(file_path)) 299 | encrypt_txt_files(file_path) 300 | print("File encrypted") 301 | resultlist = [] 302 | test, list = change_file_extension(file_path, "AAAAA") 303 | resultlist.append(list) 304 | print("Would you like to encrypt the following files? (y/n)") 305 | # Get directory of file_path 306 | dir_path = os.path.dirname(file_path) 307 | files = os.listdir(dir_path) 308 | for i in files: 309 | print(i) 310 | choice = input() 311 | base = os.path.basename(file_path) 312 | json_name = base + ".json" 313 | file_dir = os.path.dirname(file_path) 314 | os.chdir(file_dir) 315 | if choice == "y": 316 | for i in files: 317 | if os.access(i, os.W_OK): 318 | if json_name in i: 319 | print("{} is a config file for decryption. Skipping.".format(i)) 320 | continue 321 | if i.endswith(".AAAAA"): 322 | print("File {} already encrypted".format(i)) 323 | else: 324 | print("Encrypting file {}".format(i)) 325 | encrypt_txt_files(i) 326 | print("File {} encrypted".format(i)) 327 | # Get path of i 328 | path = os.path.join(file_dir, i) 329 | test, list = change_file_extension(path, "AAAAA") 330 | print("File " + i + " extension changed") 331 | resultlist.append(list) 332 | else: 333 | print("düt") 334 | print("Files listed encrypted") 335 | else: 336 | pass 337 | os.chdir(file_dir) 338 | with open(json_name, "w") as f: 339 | f.write(json.dumps(resultlist)) 340 | print("PLEASE DO NOT DELETE THE JSON FILE FOR FUTURE DECRYPTION") 341 | print("Encryption complete") 342 | print("Press 3 to exit, press 2 to return to main menu") 343 | choice = input() 344 | if choice == "3": 345 | flag = False 346 | elif choice == "2": 347 | flag = True 348 | elif choice == "2": 349 | root = tk.Tk() 350 | root.withdraw() 351 | folder_path = filedialog.askdirectory() 352 | print("Do you want subdirectories too or no?, just press 1 for yes or 2") 353 | choice = int(input()) 354 | if choice == 1: 355 | resultlist = [] 356 | print("Result list created...") 357 | subfolders = [f.path for f in os.scandir(folder_path) if f.is_dir()] 358 | print("Subfolders scanned...") 359 | for subfolder in subfolders: 360 | print("Encrypting files in " + subfolder) 361 | for subfolder in subfolders: 362 | # Get files in subfolders 363 | files = [f.path for f in os.scandir(subfolder) if f.is_file()] 364 | print("Files in " + subfolder + " scanned...") 365 | for file in files: 366 | # Get directory of file 367 | file_dir = os.path.dirname(file) 368 | os.chdir(file_dir) 369 | print("Encrypting file " + file) 370 | encrypt_txt_files(file) 371 | print("File " + file + " encrypted") 372 | test, list = change_file_extension(file, "AAAAA") 373 | print("File " + file + " extension changed") 374 | resultlist.append(list) 375 | # Get dir name 376 | dir_name = os.path.basename(subfolder) 377 | os.chdir(subfolder) 378 | json_name = dir_name + "_ext.json" 379 | with open(json_name, "w") as f: 380 | f.write(json.dumps(resultlist)) 381 | resultlist = [] 382 | # Scan base directory 383 | files = [f.path for f in os.scandir(folder_path) if f.is_file()] 384 | for file in files: 385 | encrypt_txt_files(file) 386 | test, list = change_file_extension(file, "AAAAA") 387 | resultlist.append(list) 388 | basedir_name = os.path.basename(folder_path) 389 | json_base_name = basedir_name + "_ext.json" 390 | os.chdir(folder_path) 391 | with open(json_base_name, "w") as f: 392 | f.write(json.dumps(resultlist)) 393 | print("Encryption complete") 394 | print("PLEASE DO NOT DELETE THE JSON FILE FOR FUTURE DECRYPTION") 395 | print("Press 3 to exit, press 2 to return to main menu") 396 | choice = input() 397 | if choice == "3": 398 | flag = False 399 | elif choice == "2": 400 | flag = True 401 | elif choice == 2: 402 | # Iterate through every file on folder_path with scandir 403 | files = [f.path for f in os.scandir(folder_path) if f.is_file()] 404 | print("Files scanned...") 405 | resultlist = [] 406 | for file in files: 407 | print("Encrypting file " + file) 408 | encrypt_txt_files(file) 409 | print("File " + file + " encrypted") 410 | test, list = change_file_extension(file, "AAAAA") 411 | print("File " + file + " extension changed") 412 | resultlist.append(list) 413 | os.chdir(folder_path) 414 | # Get name of folder 415 | folder_name = os.path.basename(folder_path) 416 | extension_json = folder_name + ".json" 417 | with open(extension_json, "w") as f: 418 | f.write(json.dumps(resultlist)) 419 | print("Encryption complete") 420 | print("Press 3 to exit, press 2 to return to main menu") 421 | choice = input() 422 | if choice == "3": 423 | flag = False 424 | elif choice == "2": 425 | flag = True 426 | elif choice == "3": 427 | initial_message = "Enter the message you want to encrypt, save and close the editor when you are done." 428 | edited_message = click.edit(initial_message) 429 | encrypt_messages(edited_message) 430 | # Change extension when done 431 | change_file_extension("message.txt", "AAAAA") 432 | print("Encryption complete, encrypted text is in the file 'message.AAAAA'") 433 | print("Press 3 to exit, press 2 to return to main menu") 434 | choice = input() 435 | if choice == "3": 436 | flag = False 437 | elif choice == "2": 438 | flag = True 439 | else: 440 | print("Please enter a valid choice") 441 | elif choice == "2": 442 | print("Please choose if you want to decrypt a file or a folder") 443 | print("1. File") 444 | print("2. Folder") 445 | choice = input() 446 | if choice == "1": 447 | root = tk.Tk() 448 | root.withdraw() 449 | file_path = filedialog.askopenfilename() 450 | os.chdir(os.path.dirname(file_path)) 451 | # Find extension file that ends with json 452 | extension_json = [f for f in os.listdir(os.getcwd()) if f.endswith(".json")] 453 | if len(extension_json) == 0: 454 | print("No file with .json extension found,original extension cannot be recovered") 455 | print("Press 3 to exit, press 2 to return to main menu") 456 | choice = input() 457 | if choice == "3": 458 | flag = False 459 | elif choice == "2": 460 | flag = True 461 | else: 462 | # Find extension file that ends with json 463 | os.chdir(file_path) 464 | extension_json = [f for f in os.listdir(os.getcwd()) if f.endswith(".json")] 465 | with open(extension_json[0], "r") as f: 466 | extension_json = json.loads(f.read()) 467 | # Remove extension on file_path 468 | # Search file_path in extension_json for extension 469 | for i in range(len(extension_json)): 470 | if file_path in extension_json[0][i]: 471 | extension = extension_json[0][i][file_path] 472 | # Change file extension with new extension 473 | change_file_extension(file_path, extension) 474 | # Delete .AAAAA from end of the file_path 475 | file_path = file_path[:-5] 476 | # Add extension to file_path 477 | file_path = file_path + extension 478 | # Decrypt file 479 | decrypt_txt_file(file_path) 480 | os.remove(extension_json[0]) 481 | print("Decryption complete") 482 | print("Press 3 to exit, press 2 to return to main menu") 483 | choice = input() 484 | if choice == "3": 485 | flag = False 486 | elif choice == "2": 487 | flag = True 488 | elif choice == "2": 489 | print("Do you want subdirectories too or no?, just press 1 for yes or 2") 490 | choice = int(input()) 491 | if choice == 1: 492 | root = tk.Tk() 493 | root.withdraw() 494 | folder_path = filedialog.askdirectory() 495 | subfolders = [f.path for f in os.scandir(folder_path) if f.is_dir()] 496 | for subfolder in subfolders: 497 | # Get basename of subfolder 498 | basename = os.path.basename(subfolder) 499 | extension_json = basename + "_ext.json" 500 | # Find files in subfolder 501 | files = [f.path for f in os.scandir(subfolder) if f.is_file()] 502 | for file in files: 503 | os.chdir(subfolder) 504 | if len(extension_json) == 0: 505 | print("No file with .json extension found,original extension cannot be recovered") 506 | print("Press 3 to exit, press 2 to return to main menu") 507 | choice = input() 508 | if choice == "3": 509 | flag = False 510 | elif choice == "2": 511 | flag = True 512 | else: 513 | os.chdir(subfolder) 514 | # Find extension file that ends with json 515 | with open(extension_json, "r") as f: 516 | extension_json_data = json.loads(f.read()) 517 | # Search file_path in extension_json for extension 518 | for i in range(len(extension_json_data)): 519 | if file in extension_json_data[i][0]: 520 | extension = extension_json_data[i][0][file] 521 | # Change file extension with new extension 522 | change_file_extension(file, extension) 523 | # Delete .AAAAA from end of the file_path 524 | file = file[:-5] 525 | # Add extension to file_path 526 | file = file + extension 527 | # Decrypt file 528 | decrypt_txt_file(file) 529 | os.remove(extension_json) 530 | basename = os.path.basename(folder_path) 531 | extension_json = basename + "_ext.json" 532 | os.chdir(folder_path) 533 | # Scan files in folder_path 534 | files = [f.path for f in os.scandir(folder_path) if f.is_file()] 535 | for file in files: 536 | if os.access(file, os.W_OK) and os.access(file, os.R_OK): 537 | if len(extension_json) == 0: 538 | print("No file with .json extension found,original extension cannot be recovered") 539 | print("Press 3 to exit, press 2 to return to main menu") 540 | choice = input() 541 | if choice == "3": 542 | flag = False 543 | elif choice == "2": 544 | flag = True 545 | else: 546 | os.chdir(subfolder) 547 | # Find extension file that ends with json 548 | with open(extension_json, "r") as f: 549 | extension_json_data = json.loads(f.read()) 550 | # Search file_path in extension_json for extension 551 | for i in range(len(extension_json_data)): 552 | if file in extension_json_data[i][0]: 553 | extension = extension_json_data[i][0][file] 554 | # Change file extension with new extension 555 | change_file_extension(file, extension) 556 | # Delete .AAAAA from end of the file_path 557 | file = file[:-5] 558 | # Add extension to file_path 559 | file = file + extension 560 | # Decrypt file 561 | decrypt_txt_file(file) 562 | else: 563 | pass 564 | os.remove(extension_json) 565 | print("Decryption complete") 566 | print("Press 3 to exit, press 2 to return to main menu") 567 | choice = input() 568 | if choice == "3": 569 | flag = False 570 | elif choice == "2": 571 | flag = True 572 | elif choice == 2: 573 | root = tk.Tk() 574 | root.withdraw() 575 | folder_path = filedialog.askdirectory() 576 | # Iterate through every file on folder_path with scandir 577 | # Scan files in folder_path 578 | files = [f.path for f in os.scandir(folder_path) if f.is_file()] 579 | # Find extension file that ends with json 580 | extension_jsonify = [f for f in os.listdir(folder_path) if f.endswith(".json")] 581 | if len(extension_jsonify) == 0: 582 | print("No file with .json extension found,original extension cannot be recovered") 583 | print("Press 3 to exit, press 2 to return to main menu") 584 | choice = input() 585 | if choice == "3": 586 | flag = False 587 | elif choice == "2": 588 | flag = True 589 | for file in files: 590 | os.chdir(folder_path) 591 | # Find extension file that ends with json 592 | with open(extension_jsonify[0], "r") as f: 593 | extension_json = json.loads(f.read()) 594 | # Search file_path in extension_json for extension 595 | for i in range(len(extension_json)): 596 | if file in extension_json[i][0]: 597 | extension = extension_json[i][0][file] 598 | # Change file extension with new extension 599 | change_file_extension(file, extension) 600 | # Delete .AAAAA from end of the file_path 601 | file_path = file[:-5] 602 | # Add extension to file_path 603 | file_path = file_path + extension 604 | # Decrypt file 605 | decrypt_txt_file(file_path) 606 | os.remove(extension_jsonify[0]) 607 | print("Decryption complete") 608 | # Delete extension file 609 | print("Press 3 to exit, press 2 to return to main menu") 610 | choice = input() 611 | if choice == "3": 612 | flag = False 613 | elif choice == "2": 614 | flag = True 615 | else: 616 | print("Please enter a valid choice") 617 | elif choice == "3": 618 | flag = False 619 | sys.exit() 620 | --------------------------------------------------------------------------------