-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
84 lines (68 loc) · 2.64 KB
/
helpers.py
File metadata and controls
84 lines (68 loc) · 2.64 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
78
79
80
81
82
83
84
import random
import numpy
import secrets
CHARS_LIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+=~`{}[]|:;<>?/ .,'"
def string_shuffler(seed):
res = list(CHARS_LIST)
random.Random(seed).shuffle(res)
return res
def seed_generator(inp, n):
def seed_preprocessor(arg):
if type(arg) == str:
chars = string_shuffler(6835525)
arg_num_list = []
for char in arg:
if char == '"':
ch = '/'
num = chars.index(ch)
arg_num_list.append(str(num))
elif char == '\\':
ch = '/'
num = chars.index(ch)
arg_num_list.append(str(num))
else:
num = chars.index(char)
arg_num_list.append(str(num))
pre_num = ''.join(arg_num_list) # returns a string of digits from arg
pre_num = int(pre_num)
elif type(arg) == int: # shuffle chars_list based on arg and take first 16 chars
chars = string_shuffler(arg)
f16 = chars[:15]
arg_num_list = []
for char in f16:
if char == '"':
ch = '/'
num = CHARS_LIST.index(ch)
arg_num_list.append(str(num))
elif char == '\\':
ch = '/'
num = CHARS_LIST.index(ch)
arg_num_list.append(str(num))
else:
num = CHARS_LIST.index(char)
arg_num_list.append(str(num))
pre_num = ''.join(arg_num_list) # returns a string of digits from arg
pre_num = int(pre_num)
# scale final_num down... using random.seed
random.seed(pre_num)
final_num = random.randint(0, 999999999)
return final_num
numpy.random.seed(seed_preprocessor(inp))
res = []
for i in range(n):
res.append(numpy.random.randint(0, 999999999))
return res
def rand_char():
return secrets.choice(CHARS_LIST)
def delimiter(delim_seed, delim_size=10):
"""There is a chance that this delimiter will be generated randomly in another part of the string, as part of the
encryption rounds, however the probability is only 1 in 48.398 quintillion, for a delimiter of 10 characters. It is
highly unlikely it will ever happen."""
numpy.random.seed(delim_seed)
nums = []
for k in range(delim_size):
nums.append(numpy.random.randint(len(CHARS_LIST)))
chars = []
for j in nums:
chars.append(CHARS_LIST[j])
return ''.join(chars)