├── README.md └── ramen.py /README.md: -------------------------------------------------------------------------------- 1 | 2 | **texRAMEN** 3 | ----- 4 | 5 | texRAMEN (text random encryption) is a simple text encryption program that, rather than using a password, generates a file full of metadata to reassemble the text. Without the meta file, the data is completely useless. As such, it can be secured physically on a hard drive, CD, phone, in the cloud, etc. The goal here was not to create the next big thing in cryptography; but instead to add another layer of protection on top of standard file encryption. 6 | 7 | **To install:** 8 | 9 | Simply mark the file as executable (usually `chmod +x`) and run it. It has no special dependencies outside of `touch` and `python3`. 10 | -------------------------------------------------------------------------------- /ramen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import random 3 | import os 4 | import re 5 | import shlex 6 | 7 | # Universal constant referenced further on, this is a list of every character 8 | # considered "valid" 9 | valid_chars = list('1234567890abcdefghijklmnopqrstuvwxyz' + 10 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') 11 | 12 | print('''\ 13 | 14 | Welcome To: 15 | 16 | ( ' * ) 17 | )\ ) ( ( ` ( /( 18 | (()/( )\ )\))( ( )\()) 19 | /(_))((((_)( ((_)()\ )\ ((_) | 20 | (_)) )\ _ )\ (_()((_)((_) _((_) 21 | | _ \ (_)_\(_)| \/ || __|| \| | 22 | | / / _ \ | |\/| || _| | .` | 23 | |_|_\ /_/ \_\ |_| |_||___||_|\_| 24 | 25 | RAndoM ENcryption\n\n''') 26 | 27 | print('DISCLAIMER: RAMEN IS NOT TRUE CRYPTOGRAPHY.\n \ 28 | It is human proof, not computer proof.') 29 | 30 | # Generate a string of x random characters 31 | 32 | 33 | def rand_str(x): 34 | randstr = ''.join(random.choice(valid_chars) for n in range(x)) 35 | return randstr 36 | 37 | # GIGANTIC CAUTION SIGN BECAUSE OF THE NATURE OF THE PROGRAM 38 | 39 | 40 | def caution(): 41 | print(''' 42 | *=================================================================* 43 | |/ / / / / / / / / / / / / / / / / / / / / / | 44 | | / / / / / / / / / / / / / / / / / / / / / | 45 | | / / / / / / / / / / / / / / / / / / / / / /| 46 | |/ / / / / / / / C A U T I O N ! ! ! / / / / / / / | 47 | | / / / / / / / / / / / / / / / / / / / / / | 48 | | / / / / / / / / / / / / / / / / / / / / / /| 49 | |/ / / / / / / / / / / / / / / / / / / / / / | 50 | *=================================================================*''') 51 | return True 52 | 53 | # Determine if user wishes to encrypt or decrypt their text file 54 | print('Would you like to encrypt or decrypt a text file? (e/d)') 55 | e_or_d = '' 56 | while True: 57 | e_or_d = input(': ') 58 | if e_or_d.lower() in 'ed': 59 | break 60 | print('The path to your file can be relative to the RAMEN directory.') 61 | # Proceed with encryption 62 | if e_or_d == 'e': 63 | print('Please note that any formatting will not be kept in this version.') 64 | file_loc = '' 65 | # The code was much nicer when the output files couldn't have an extension. 66 | while True: 67 | print('What is the location of the textfile that you wish to encrypt?') 68 | file_loc = input(': ') 69 | does_file_exist = os.path.isfile(file_loc) 70 | if does_file_exist is True: 71 | if '.' in file_loc: 72 | fname, fext = os.path.splitext(file_loc) 73 | break 74 | else: 75 | fname, fext = os.path.splitext(file_loc) 76 | fext = '' 77 | else: 78 | print('Please reenter, the file location you gave does not exist.') 79 | os.system('touch {0}_temp{1} && touch {0}_meta{1}'.format( 80 | shlex.quote(fname), shlex.quote(fext))) 81 | temp = '' 82 | with open(file_loc, 'r') as f: 83 | temp = f.read().replace('\n', '') 84 | temp_list = re.findall(r"[\w']+|[.,!?;:]", temp) 85 | # Open fname_temp and fname_meta 86 | with open(fname + '_temp' + fext, 'a') as f, \ 87 | open(fname + '_meta' + fext, 'a') as f2: 88 | for idx, word in enumerate(temp_list): 89 | word_list = list(word) 90 | # Adds a random string in between every character in file. 91 | # This makes the output text indecipherable without the meta file. 92 | for char in word_list: 93 | rand_str_loop = rand_str(random.randint(5, 20)) 94 | f.write('{}{}'.format(char, rand_str_loop)) 95 | f2.write('{}\n'.format(rand_str_loop)) 96 | f.write('r4M#') 97 | os.system('rm {0}{1} && mv {0}_temp{1} {0}{1}'.format(fname, fext)) 98 | print('\nEncryption complete at {}'.format(file_loc) + 99 | '\n\nThank you for using RAMEN.\n') 100 | caution() 101 | print('If you lose your _meta file, you will NOT be able to recover\n \ 102 | your data! I, the creator, am not responsible for this.\n') 103 | print('Also, please do not change the formatting of either file. I \ 104 | cannot\n guarantee the decryption process will work if you do.') 105 | 106 | # Proceed with decryption 107 | else: 108 | caution() 109 | print('IT IS RECOMMENDED YOU BACK UP YOUR FILES BEFORE DOING THIS!!!\n \ 110 | IN THE EVENT THERE IS AN ERROR, YOUR DATA WILL BECOME UNREADABLE.\n \ 111 | PROCEED WITH CAUTION.') 112 | # Learn the location of the file to be decrypted 113 | file_loc = '' 114 | while True: 115 | print('What is the location of the text file that you wish to \ 116 | decrypt? \n(This software isn\'t magic. It requires the RAMEN meta file.)') 117 | file_loc = input(': ') 118 | does_file_exist = os.path.isfile(file_loc) 119 | if does_file_exist is True: 120 | fname, fext = os.path.splitext(file_loc) 121 | break 122 | else: 123 | print('Please reenter, the file location you gave does not exist.') 124 | # Learn the location of the meta file 125 | meta_loc = '' 126 | is_meta_same_format = input('Is the meta file location the same as the \ 127 | first one & \"_meta\"? (y/n) :') 128 | if is_meta_same_format in 'Yy': 129 | meta_loc = fname + '_meta' + fext 130 | else: 131 | while True: 132 | print('What is the location of the meta file?\n \ 133 | (It should simply be \"folder/file_meta\")') 134 | meta_loc = input(': ') 135 | does_file_exist = os.path.isfile(meta_loc) 136 | if does_file_exist is True \ 137 | and '_meta' in meta_loc: 138 | break 139 | else: 140 | print('Please re-enter, the file location you gave does not \ 141 | exist or is not a _meta file.\n \ 142 | If you do not have the _meta file, your data is lost.') 143 | os.system('touch {}_temp{}'.format(fname, fext)) 144 | data = '' 145 | meta = '' 146 | # Read the file and meta file in the user-given location. 147 | with open(file_loc, 'r') as f, \ 148 | open(fname + '_temp' + fext, 'a') as f_t, \ 149 | open(meta_loc, 'r') as m: 150 | data = f.read().split('r4M#') 151 | meta = m.read().splitlines() 152 | # This works by comparing the values in the meta file with how the 153 | # data starts. If the data starts with a value in the meta file, it 154 | # erases that random string and then writes the next letter to the 155 | # output file. 156 | for idx, word in enumerate(data): 157 | try: 158 | if idx == 0: 159 | f_t.write(list(word)[0]) 160 | else: 161 | f_t.write(' {}'.format(list(word)[0])) 162 | except: 163 | pass 164 | word = word[1:] 165 | try: 166 | for line in meta: 167 | if word.startswith(line): 168 | word = word[len(line):] 169 | f_t.write(list(word)[0]) 170 | word = word[1:] 171 | except IndexError: 172 | pass 173 | f_t.write('\n') 174 | os.system('rm {0} && rm {1} && mv {2}_temp{3} {0}'.format( 175 | shlex.quote(file_loc), shlex.quote(meta_loc), shlex.quote(fname), 176 | shlex.quote(fext))) 177 | 178 | print('Your file: {} has been decrypted and the original meta file has \ 179 | been removed.\n'.format(file_loc) + 180 | 'Thanks for using RAMEN.') 181 | --------------------------------------------------------------------------------