forked from Geonaute/WPA-ro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoA.py
310 lines (264 loc) · 7.55 KB
/
RoA.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
"""
R --------- R
O O ------ O
N C A --- A
D C L
O U G +Copyright SavSec (c) 2017
M r O
E R +Algorithms are intellectual
N I so no Copyright except
C T directly to ownership of the
E H base algorithm.
M -MIT License-
"""
import time, random, sys, string, itertools, os
import base64, hashlib
from Crypto import Random
from Crypto.Cipher import AES
class AESCipher (object):
def __init__(self, key):
self.bs = 32
self.key = key
def encrypt(self, raw):
raw = self._pad(raw)
iv = Random.new().read(AES.block_size)
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return base64.b64encode(iv + cipher.encrypt(raw))
def decrypt(self, enc):
enc = base64.b64decode(enc)
iv = enc[:AES.block_size]
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return self._unpad(cipher.decrypt(enc[AES.block_size:])).decode("utf-8")
def _pad(self, s):
return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs)
@staticmethod
def _unpad(s):
return s[:-ord(s[len(s)-1:])]
class RoA (object):
"""
RoA / Random Occurence Algorithm is an algorithm developed by Russian Otter! This basic algorithm generates random data based on the exponential outputs given from the algorithm!
Requirements To Decrypt:
1.) AES Key
2.) RoA Key
3.) Salt
4.) Encrypted Dictionary
"""
def __init__(self,verbose=False):
"""
Setting this option to True makes RoA display all active activities!
"""
self.verbose = verbose
def algorithm(self,tm,base_length):
"""
RoA.algorithm(3 Digits, Key Length) -> Numeric Algorithm Output
This is how RoA generates it's data! The output to RoA is simular to Pi in the fact that it doesnt end and doesnt repeat!
"""
base = ""
d = ".".join("`"*i+" "[i : i+i] for i in range(0,125,random.randint(1,4)))+ ".".join("`"*i+" "[i : i] for i in range(0,125,random.randint(1,10)))
b = "".join(d[a : i] for i in range(0,10+tm,2) for a in range(i+~-i*i))
for _ in "".join(b[i:i+i] for i in range(0,tm+base_length,2)):
base += _
time.sleep(0.000005)
base = base[:base_length]
n = ""
for _ in range(tm):
n += str("".join(random.sample(base,random.choice(range(len(base))))).count("."))
time.sleep(0.0005)
try:
n = hex(int(n))[2:].replace("L","")[:base_length]
except:
return n
while 1:
if len(n) == base_length:
break
n += random.choice(string.hexdigits.lower())
return n[:base_length]
def generate_key(self,AESkey):
"""
RoA.generate_key(32bit AES Key)
This is used to general the basic RoA Encryption Key
"""
if len(AESkey) != 32:
raise "AESkey length is %s. 32 bit key is required!"
tm = random.choice(range(0,100))
if len(str(tm)) == 2 and tm < 77:
tm = int("0"+str(tm))
if len(str(tm)) == 1:
tm = int("00"+str(tm))
key = self.algorithm(tm,16)
key = key + AESkey
return key
def encrypt(self,msg,key):
"""
RoA.Encrypt(message, RoAKey)
This is the main encryption process of RoA which makes it secure
"""
if self.verbose:
print "Master Key:",key
print "\nAES Key:",key[16:]
print "\nRoA Key:",key[:16]
print "\nEncrypting Message in AES..."
AESKey = key[16:]
rokey = key[:16] *2
aes = AESCipher(key[16:])
en_msg = aes.encrypt(msg)
if self.verbose:
print "\nEncrypted AES:",en_msg
print "\nApplying Salt Mix..."
msg = en_msg
frag = None
while 1:
for _ in range(4,9):
l = len(msg)/float(_)
if l.is_integer():
frag = _
msg += b"\x01"
if frag != None:
break
sp = len(msg)/frag
fragged = []
salt = []
while 1:
pun = True
for _ in msg:
if _ in string.punctuation:
t = "".join(random.sample(string.ascii_letters + string.digits + string.punctuation.strip("}").strip("'").strip("\"") +b"\x01",7))
pun = False
break
if pun:
t = "".join(random.sample(string.ascii_letters + string.digits+b"\x01",7))
if t not in "".join(msg):
salt.append(t)
if len(salt) > 15:
break
prev = 0
while True:
f = random.randint(1,sp)
fragged.append(msg[prev:prev+f])
prev = prev + f
if prev >= len(msg)-1:
break
if self.verbose:
print "Fragmented Text:"
print fragged
print "\nSalt & Pepper:"
print salt
refrag = {}
def shuffled(x):
y = x[:]
random.shuffle(y)
return y
x = shuffled(fragged)
for _ in fragged:
for i in x:
if i == _:
refrag.update(
{str(x[x.index(_)]
):fragged.index(i)})
if self.verbose:
print "\nMixed Fragments:"
print x
print "\nDictionary:"
print refrag
comp_refrag = str(refrag).replace(", '",",'")
comp_salt = str(salt).replace(", '",",'")
comp_dict = comp_refrag+b"\x02"+comp_salt.strip("\n")
if self.verbose:
print "\nCompressed Dictionary:"
print comp_dict
salt_mix = ""
sl = 0
for _ in x:
if sl > len(salt)-1:
sl = 0
salt_mix += _+salt[sl]
sl = sl + 1
if self.verbose:
print "\nSalted Text:"
print salt_mix
aessalt = AESCipher(rokey)
en_comp_dict = aessalt.encrypt(comp_dict)
en_salt = aessalt.encrypt(salt_mix)
if self.verbose:
print "\nEncrypted Dictionary:"
print en_comp_dict
print "\nEncrypted Salt:"
print en_salt
return en_salt+b"\x03"+en_comp_dict,rokey,AESKey
def decrypt(self,en_saltdict,key,AESKey):
"""
RoA.decrypt(encrypted salt dictionary, RoA Key, AES Key)
This fuction process reverses all the past actions based on the information it decrypts
"""
en_comp_dict = en_saltdict.split(b"\x03")[1]
en_salt = en_saltdict.split(b"\x03")[0]
aessalt = AESCipher(key)
comp_dict = aessalt.decrypt(en_comp_dict)
aessalt = AESCipher(key)
salt_mix = aessalt.decrypt(en_salt)
if self.verbose:
print "\n - Starting Decryption Process -"
print "\nCollecting Dictionary Data..."
de_dict = eval(comp_dict.split(b"\x02")[0])
water = eval(comp_dict.split(b"\x02")[1])
de_salt = salt_mix
remain = []
if self.verbose:
print "Diluting Salt..."
for _ in water:
de_salt = de_salt.replace(_,"")
if self.verbose:
print "Re-arranging Text..."
c = 0
en_txt = ""
for _ in de_dict:
for _ in de_dict:
if de_dict[_] == c:
en_txt += _
c = c + 1
aes = AESCipher(AESKey)
de_txt = aes.decrypt(en_txt)
if self.verbose:
print "\nEncrypted Text:"
print en_txt
print "\nDecrypting..."
print "\nDecrypted Text:"
print de_txt
return de_txt
Ro = RoA(True)
def example():
Ro = RoA(True)
saltdic = Ro.encrypt("Follow @Russian_Otter on Instagram!",Ro.generate_key("PythonRo"*4))
time.sleep(5)
decrypted = Ro.decrypt(saltdic[0],saltdic[1],saltdic[2])
def pattern_test():
import matplotlib.pyplot as plt
import numpy as np
amount = "\r\r\ra: %s b: %s c: %s d: %s e: %s f: %s 1: %s 2: %s 3: %s 4: %s 5: %s 6: %s 7: %s 8: %s 9: %s 0: %s "
for _ in range(100):
key = Ro.algorithm(10,16)
f = open("tmp.bit","a")
f.write(key)
f.close()
total = open("tmp.bit").read()
a = amount.replace(" "," | ")
t = total
data = a % (t.count("a"),t.count("b"),t.count("c"
),t.count("d"),t.count("e"),t.count("f"),t.count("1"),t.count("2"
),t.count("3"),t.count("4"),t.count("5"),t.count("6"),t.count("7"),t.count("8"),t.count("9"),
t.count("0"))
sys.stdout.write(data)
time.sleep(0.00005)
t = data.split(" | ")
alphab = list("abcdef1234567890")
frequencies = []
for _ in range(1,32,2):
frequencies.append(int(t[_].replace(" ","")))
pos = np.arange(len(alphab))
width = 1.0
ax = plt.axes()
ax.set_xticks(pos + (width / 1))
ax.set_xticklabels(alphab)
plt.bar(pos, frequencies, width, color="lime")
plt.show()
os.remove("./tmp.bit")