forked from bipbop/jurischain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenstats.py
63 lines (42 loc) · 1.37 KB
/
genstats.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
import os
import subprocess
import json
import matplotlib.pyplot as plt
from multiprocessing import Pool
def calculate(seed):
result = []
s = f"{str(seed)}"
for i in range(1, 23):
print(f"[*] Seed: {s} [{i}/22]")
command = ["./sha3", f"{i}", f"{seed}"]
res = subprocess.check_output(command).splitlines()
diff = int(str(res[0]).split(':')[1].strip("'"))
tries = int(str(res[3]).split(':')[1].strip("'"))
assert diff == i
result.append((diff, tries))
return result
def generate_data():
seeds = [os.urandom(32) for s in range(10)]
print("[*] Generating data...")
p = Pool(10)
result = p.map(calculate, seeds)
results = {x: 0 for x in range(1,23)}
for seed in result:
for pair in seed:
results[pair[0]] += pair[1]
for diff in results.keys():
results[diff] = results[diff]/22
return results
def generate_graph():
data = generate_data()
if not os.path.exists('stats/'):
os.makedirs('stats/')
with open('stats/dataset.txt', 'w') as dataset:
json.dump(data, dataset)
means = [x for x in data.values()]
plt.semilogy([x for x in range(len(means))], means)
plt.title('Average tries per challenge difficulty')
plt.xlabel('Difficulty')
plt.ylabel('Tries')
plt.savefig('stats/statistics.png')
generate_graph()