-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
112 lines (73 loc) · 3.49 KB
/
main.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from random import shuffle
with open('private_keys.txt') as file:
private_keys = [i.strip() for i in file.readlines()]
class Key:
def __init__(self, digits: list, symbols: list) -> None:
self.digits = digits
self.symbols = symbols
self.first_part, self.second_part = {}, {}
def main(self, private_keys: list) -> list:
encrypted_keys = []
self.second_symbols = self.symbols.copy()
shuffle(self.second_symbols)
for key in private_keys:
encrypted = self.encrypting(key)
encrypted_keys.append(encrypted)
self.configure_decrypt()
return encrypted_keys
def encrypting(self, key: str) -> str:
half = len(key)//2
key_first_part = key[:half]
key_second_part = key[half:]
for num in range(len(self.digits)):
self.first_part[self.symbols[num]] = self.digits[num]
self.second_part[self.second_symbols[num]] = self.digits[num]
key_first_part = key_first_part.replace(self.digits[num], self.symbols[num])
key_second_part = key_second_part.replace(self.digits[num], self.second_symbols[num])
encrypted_key = key_first_part + key_second_part
return encrypted_key
def configure_decrypt(self) -> None:
print('\n' + '='*150 + '\n\n' + ' '*60 + '|||Your decrypt function`s below|||\n\n' + '='*150)
print(rf'''
first_part = {self.first_part}
second_part = {self.second_part}
def decrypting(key: str) -> str:
half = len(key)//2
first_part_keys = list(first_part.keys())
key_first_part = key[:half]
key_second_part = key[half:]
for symbol in first_part_keys:
key_first_part = key_first_part.replace(symbol, first_part[symbol])
key_second_part = key_second_part.replace(symbol, second_part[symbol])
encrypted_key = key_first_part + key_second_part
return encrypted_key
with open('encrypted_keys.txt') as file:
private_keys = [decrypting(i.strip()) for i in file.readlines()]
# ^^^^^^^^^^^^ change this variable to variable in your code
# |||||||||||| ex: KEYS
# code below is just for decrypt. if you need to paste this code in your script, just delete code below
with open('private_keys.txt', 'w') as file:
file.write('\n'.join(private_keys))
''')
if __name__ == '__main__':
# each digit only once. ex: 0123 or 6234 or 435216 etc. No more than 10
digits = [i for i in input('Type the digits for replace:\n')]
[exit(print('You chose equal digits twice'))
for i in digits if digits.count(i) > 1]
# each symbol only once. ex: $<:>|#@! . No more than 10
# must be equal to the count of digits.
symbols = [i for i in input("\n" + r"Type the symbols (don`t use '\'):" + "\n")]
[exit(print('You chose equal symbols twice'))
for i in symbols if symbols.count(i) > 1]
[exit(print('You chose symbols&symbols or digits&digits'))
for i in symbols if i in digits]
if len(digits) != len(symbols):
exit(print('Digits count must be equal to symbols'))
elif 1 > len(digits) > 10:
exit(print('You chose wrong digits count'))
else:
print(f'\nYou chose these digits {digits}\n'
f'You chose these symbols: {symbols}')
encrypted_keys = Key(digits, symbols).main(private_keys)
with open('encrypted_keys.txt', 'w') as file:
file.write('\n'.join(encrypted_keys))