-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
110 lines (88 loc) · 3.07 KB
/
test.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
from random import randint
from time import time
from tqdm import tqdm
## coloured text vars
CEND = '\u001b[0m'
CRED = '\u001b[31m'
CGRN = '\u001b[32m'
CBLU = '\u001b[34m'
loc = r"C:\droneshit\test.txt"
block = 128 # default read block size in bytes
###############################################################
def ranNumGen(numdigits):
'Custom, cryptographically-secure random number generator.'
# turn epoch into one number (remove the decimal point)
epoch = str(time()).replace(".", "") # epoch time
epoch = int(epoch)
# we're making this a function so it can be repeated as neccesary to reach the ideal number of digits (numdigits)
def makeShitHappen():
memBit = "0b"
# generate random binary number
for i in range(len(str(epoch))):
epoch_s = str(epoch)[randint(0, len(str(epoch))-1)] + str(epoch)[randint(0, len(str(epoch))-1)]
epoch_s = int(epoch_s)
mask = 1 << 0
is_set = (int(epoch_s) & mask) != 0
if(is_set):
memBit += "1"
else:
memBit += "0"
# make binary number an integer
memBit = (int(memBit, 2))
return memBit
# get to ideal number of digits (numdigits)
rannum = makeShitHappen()
while(len(str(rannum)) != numdigits):
if(len(str(rannum)) < numdigits):
rannum += makeShitHappen()
elif(len(str(rannum)) > numdigits):
rannum = str(rannum)
rannum = rannum.replace(rannum[randint(0, len(rannum)-1)], "")
rannum = int(rannum)
else:
break
return rannum
def proccessFileChunk(loc, block):
with open(loc, "r") as f:
while True:
chunk = f.read(block)
if not chunk:
break
yield chunk
###############################################################
## runtest vars
ranGen = False
readChunks = True
def runTest(ranGen, readChunks):
'Runs tests of specified functions.'
if ranGen:
print(f"{CBLU}CURRENT TEST: RANNUMGEN(){CEND}")
tstcnt = 1000
t_length = 10
bins = [] # binaries
bins_l = "" # length of each integer
# generate numbers and turn into integers
for i in tqdm(range(tstcnt)):
bins.append(ranNumGen(t_length))
print(str(bins))
print(f"{CBLU}TEST 1: LENGTH CONSISTENCY{CEND}")
print(f"TARGET: {t_length}")
pas = 0
fal = 0
for i in range(len(bins)):
bins_l = str(len(str(bins[i])))
if bins_l == str(t_length):
pas += 1
else:
fal += 1
print(f"TEST 1 RESULTS: {pas} PASS / {fal} FAIL")
if(pas == tstcnt):
print(f"{CGRN}TEST 1 PASSED{CEND}")
else:
print(f"{CRED}TEST 1 FAILED{CEND}")
if readChunks:
for chunk in proccessFileChunk(loc, block):
print("\n")
print(chunk)
###############################################################
runTest(ranGen, readChunks)