-
Notifications
You must be signed in to change notification settings - Fork 0
/
get20k.py
48 lines (38 loc) · 940 Bytes
/
get20k.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
from arduino import Arduino
from stattests StatTests, FipsTests
import sys
if len(sys.argv) == 1:
print "missing alg"
sys.exit()
algorithm = sys.argv[1]
k = int(sys.argv[2])
ard = Arduino()
print algorithm
# ...
if algorithm == 'meanrand':
s = ''.join(ard.meanrand(k))
elif algorithm == 'updownrand':
s = ''.join(ard.updownrand(k))
elif algorithm == 'mix':
s = ''.join(ard.mixmeanupdown(k))
elif algorithm == 'leastsig':
s = ''.join(ard.leastsigrand(k))
elif algorithm == 'twol':
s = ''.join(ard.twoleastsignrand(k))
elif algorithm == 'vanilla':
s = ''.join(ard.vanilla(k))
if "-p" in sys.argv:
print s
st = StatTests(s)
print st.monobit()
print st.poker()
print st.runs()
fips = FipsTests(s)
print fips.monobit()
print fips.poker()
print fips.runs()
save = (sys.argv[3] if len(sys.argv) >= 4 else "") or raw_input("Save to: ")
if save:
f = open(save, 'w')
f.write(s)
f.close()