-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrypter.py
231 lines (203 loc) · 7.17 KB
/
crypter.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import base64
import hashlib
import random
import json
import string
def encrypt256(self):
sha_signature = hashlib.sha256(self.encode()).hexdigest()
return sha_signature
def encode64(self):
message_bytes = self.encode('utf-8')
base64_bytes = base64.b64encode(message_bytes)
base64_string = base64_bytes.decode('utf-8')
return base64_string
def decode64(self):
base64_message = self
base64_bytes = base64_message.encode('utf-8')
message_bytes = base64.b64decode(base64_bytes)
decoded_string = message_bytes.decode('utf-8')
return decoded_string
def encrypt(self, hash_pass):
alfa = list(string.ascii_lowercase)
# CREATE SUB_LISTS
ps1 = []
ps2 = []
ps3 = []
ps4 = []
ps5 = []
# GENERATE A SEQUENCE
for i1 in range(0, 5):
ps1.append(i1)
for i2 in range(5, 10):
ps2.append(i2)
for i3 in range(10, 15):
ps3.append(i3)
for i4 in range(15, 20):
ps4.append(i4)
for i5 in range(20, 26):
ps5.append(i5)
# RANDOMIZE SEQUENCES
random.shuffle(ps1)
random.shuffle(ps2)
random.shuffle(ps3)
random.shuffle(ps4)
random.shuffle(ps5)
# ADD SUB_LISTS TO A FINAL LIST
pswitched = []
for sq in ps1:
pswitched.append(sq)
for sq in ps2:
pswitched.append(sq)
for sq in ps3:
pswitched.append(sq)
for sq in ps4:
pswitched.append(sq)
for sq in ps5:
pswitched.append(sq)
# ENCODE BASE64
encoded_string = encode64(self)
# START ENCRYPTION
encrypted_string = ""
for letter in encoded_string:
counter = 0
found = False
for i in alfa:
if letter == i:
found = True
encrypted_string += "{}".format(alfa[pswitched[counter]])
break
elif letter == i.upper():
found = True
encrypted_string += "{}".format(alfa[pswitched[counter]].upper())
break
counter += 1
if not found:
encrypted_string += "{}".format(letter)
# ADD A HASH OF ENCRYPTED DOCUMENT TO SIGN
hash_k = encrypt256(encrypted_string)
# ADD KEY TO DECRYPT
k1 = encrypt256(hash_pass + str(ps1))
k2 = encrypt256(hash_pass + str(ps2))
k3 = encrypt256(hash_pass + str(ps3))
k4 = encrypt256(hash_pass + str(ps4))
k5 = encrypt256(hash_pass + str(ps5))
# POSITION KEYS HALF WAY OF THE ENCRYPTED STRING
position = int(len(encrypted_string) / 2)
output = "".join((encrypted_string[:position], hash_k, k1, k2, k3, k4, k5, encrypted_string[position:]))
# RESULT ENCRYPTED
return output
def decrypt(self, pswitched):
alfa = list(string.ascii_lowercase)
decoded_string = ""
for letter in self:
counter = 0
found = False
for i in alfa:
if letter == i:
found = True
position = 0
for n in pswitched:
if n == counter:
decoded_string += "{}".format(alfa[position])
break
position += 1
break
elif letter == i.upper():
found = True
position = 0
for n in pswitched:
if n == counter:
decoded_string += "{}".format(alfa[position].upper())
break
position += 1
break
counter += 1
if not found:
decoded_string += "{}".format(letter)
# RESULT ENCRYPTED
return str(decode64(decoded_string))
def get_sequence5(self, end, pwrd_hash, hash256):
plis = []
for n in range(self, end):
plis.append(n)
for loop in range(0, len(plis)):
if 0 < loop < len(plis):
plis.insert(0, plis.pop(loop))
for i in range(0, len(plis)-1):
lis = [plis[0], plis[1], plis[2], plis[3], plis[4]]
if 0 < i < len(plis)-1:
lis.insert(1, lis.pop(i+1))
ml = [lis[0], lis[1], lis[2], lis[3], lis[4]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [lis[0], lis[1], lis[2], lis[4], lis[3]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [lis[0], lis[1], lis[3], lis[2], lis[4]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [lis[0], lis[1], lis[3], lis[4], lis[2]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [lis[0], lis[1], lis[4], lis[3], lis[2]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [lis[0], lis[1], lis[4], lis[2], lis[3]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
return None
def get_sequence6(self, end, pwrd_hash, hash256):
plis = []
for n in range(self, end):
plis.append(n)
for loop in range(0, len(plis)):
if 0 < loop < len(plis):
plis.insert(0, plis.pop(loop))
for n in range(0, len(plis)-1):
lis = [plis[0], plis[1], plis[2], plis[3], plis[4], plis[5]]
if 0 < n < len(plis)-1:
lis.insert(1, lis.pop(n+1))
for i in range(0, len(lis)-1):
li = [lis[0], lis[1], lis[2], lis[3], lis[4], lis[5]]
if 0 < i < len(lis)-1:
li.insert(2, li.pop(i+1))
# COMPARE
ml = [li[0], li[1], li[2], li[3], li[4], li[5]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [li[0], li[1], li[2], li[3], li[5], li[4]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [li[0], li[1], li[2], li[4], li[3], li[5]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [li[0], li[1], li[2], li[4], li[5], li[3]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [li[0], li[1], li[2], li[5], li[4], li[3]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
ml = [li[0], li[1], li[2], li[5], li[3], li[4]]
if encrypt256(pwrd_hash+str(ml)) == hash256:
return ml
return None
def open_file(self):
with open(self, "r", encoding="utf-8") as file:
json_content = json.loads(file.read())
return str(json_content)
def get_keys(self):
position = int((len(self)-384) / 2)
hash_document = self[position:position+64]
k1 = self[position+(1*64):position + 128]
k2 = self[position+(2*64):position + 192]
k3 = self[position+(3*64):position + 256]
k4 = self[position+(4*64):position + 320]
k5 = self[position+(5*64):position + 384]
document = self[:position] + self[position+384:]
return [document, k1, k2, k3, k4, k5, hash_document]
def get_content(self):
with open(self, "r", encoding="utf-8") as file:
all_content = file.read()
return get_keys(all_content)
def get_string(self):
return get_keys(self)