├── decryptor.py ├── cli.py ├── encryptor.py └── generator.py /decryptor.py: -------------------------------------------------------------------------------- 1 | import random 2 | import json 3 | 4 | dict_file = open('my_secret_dictionary.json') 5 | my_dict = json.load(dict_file) 6 | 7 | def decrypt(text): 8 | text = text.split(" ") 9 | decrypted_text = "" 10 | for word in text: 11 | for key in my_dict: 12 | if word in my_dict[key]: 13 | decrypted_text += key 14 | 15 | return decrypted_text 16 | -------------------------------------------------------------------------------- /cli.py: -------------------------------------------------------------------------------- 1 | while True: 2 | 3 | user_input = input(""" Hello there, this is a TEXT-Encryption & Decryption system made for bad days in Iran. (@revisto) 4 | !!ONLY WOKS WITH PERSIAN LETTERS ONLY!! 5 | What do you want to do? 6 | 1. Encrypt a message 7 | 2. Decrypt a message 8 | 3. Generate a secret dictionary 9 | Your Choice: """) 10 | 11 | 12 | if user_input == "1": 13 | user_input_text = input("Ok, Now please type your message. \n Input: ") 14 | from encryptor import encrypt 15 | print(encrypt(user_input_text)) 16 | break 17 | 18 | elif user_input == "2": 19 | user_input_text = input("Ok, Now please type your encrypted message. \n Input: ") 20 | from decryptor import decrypt 21 | print(decrypt(user_input_text)) 22 | break 23 | 24 | elif user_input == "3": 25 | from generator import generator 26 | print(generator()) 27 | break 28 | 29 | else: 30 | print("Your is not valid, retry...\n") -------------------------------------------------------------------------------- /encryptor.py: -------------------------------------------------------------------------------- 1 | import random 2 | import json 3 | 4 | dict_file = open('my_secret_dictionary.json') 5 | my_dict = json.load(dict_file) 6 | 7 | 8 | def encrypt(text): 9 | text = text.split(" ") 10 | encrypted_text = "" 11 | for word in text: 12 | while word != "": 13 | if len(word) >= 3: 14 | splited_letters = word[0] + word[1] + word[2] 15 | encrypted_text += " " + random.choice(my_dict[splited_letters]) 16 | word = word[3:] 17 | 18 | elif len(word) >= 2: 19 | splited_letters = word[0] + word[1] 20 | encrypted_text += " " + random.choice(my_dict[splited_letters]) 21 | word = word[2:] 22 | 23 | else: 24 | splited_letters = word[0] 25 | encrypted_text += " " + random.choice(my_dict[splited_letters]) 26 | word = word[1:] 27 | encrypted_text += " " + random.choice(my_dict[" "]) 28 | 29 | return encrypted_text 30 | -------------------------------------------------------------------------------- /generator.py: -------------------------------------------------------------------------------- 1 | import random 2 | import json 3 | 4 | matched_words_count = 1 5 | matched_words_for_space_count = 20 6 | farsi_letters = "ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپوژ" 7 | english_letters = 'qwertyuiopasdfghjklzxcvbnm' #for future 8 | 9 | 10 | words_file = open('words.json') 11 | words = json.load(words_file) 12 | my_dictionary = dict() 13 | 14 | def generator(): 15 | 16 | for first_letter in farsi_letters: 17 | for second_letter in farsi_letters: 18 | for third_letter in farsi_letters: 19 | chosen_words = [] 20 | for i in range(matched_words_count): 21 | chosen_words.append(random.choice(words)) 22 | words.remove(chosen_words[-1]) 23 | my_dictionary[f"{first_letter}{second_letter}{third_letter}"] = chosen_words 24 | print(len(my_dictionary)) 25 | 26 | for first_letter in farsi_letters: 27 | for second_letter in farsi_letters: 28 | chosen_words = [] 29 | for i in range(matched_words_count): 30 | chosen_words.append(random.choice(words)) 31 | words.remove(chosen_words[-1]) 32 | my_dictionary[f"{first_letter}{second_letter}"] = chosen_words 33 | 34 | 35 | for first_letter in farsi_letters: 36 | chosen_words = [] 37 | for i in range(matched_words_count): 38 | chosen_words.append(random.choice(words)) 39 | words.remove(chosen_words[-1]) 40 | my_dictionary[first_letter] = chosen_words 41 | 42 | 43 | chosen_words = [] 44 | for i in range(matched_words_for_space_count): 45 | chosen_words.append(random.choice(words)) 46 | words.remove(chosen_words[-1]) 47 | my_dictionary[" "] = chosen_words 48 | 49 | 50 | with open('my_secret_dictionary.json', 'w') as fp: 51 | json.dump(my_dictionary, fp, ensure_ascii=False) 52 | 53 | return {"succuss": True, "path": "my_secret_dictionary.json"} --------------------------------------------------------------------------------