-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
77 lines (54 loc) · 2.09 KB
/
Copy pathmain.py
File metadata and controls
77 lines (54 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from data import *
from itertools import permutations
import random
def get_file_content(INPUT_PATH):
try:
with open(INPUT_PATH, 'r') as file:
return file.read()
except FileNotFoundError:
print("File not found")
def get_key_letters():
all_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', " ", '"', 1, 2, 3, 4, 5, 6, 7, 8, 9,
'[', ']', "'", "`", "!", "?", "/", "\\", "@"]
random.shuffle(all_letters)
return all_letters
def set_key():
try:
with open(TEMPLATE_PATH, 'r') as file:
new_content = file.read()
except FileNotFoundError:
print("File not found")
with open(OUTPUT_PATH, 'w') as file:
new_content = new_content.replace("Set key=THERE_WILL_BE_NEW_KEY", f"Set key={KEY}")
file.write(new_content)
def obfuscate_code(KEY_LETTERS, file_content):
global buffer
buffer = '\n'
def get_letter_id(letter):
return KEY_LETTERS.index(letter)
def make_change(letter):
global buffer
try:
letter_id = get_letter_id(letter)
template = f'%key:~{letter_id},1%'
buffer += template
except ValueError:
buffer += letter
for char in file_content:
make_change(char)
with open(OUTPUT_PATH, 'a') as file:
try:
file.write(buffer)
except FileNotFoundError:
print("File not found")
except Exception as error:
print(f"Error in {error}")
if __name__ == '__main__':
file_content = get_file_content(INPUT_PATH)
KEY_LETTERS = get_key_letters()
KEY = ''.join(str(item) for item in KEY_LETTERS)
set_key()
obfuscate_code(KEY_LETTERS.copy(), file_content)