-
Notifications
You must be signed in to change notification settings - Fork 1
/
sr.py
69 lines (56 loc) · 1.99 KB
/
sr.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
from util import *
import collections
import csv
def get_results(path):
data = collections.defaultdict(lambda: collections.defaultdict(list))
with open(path) as f:
f.readline()
reader = csv.DictReader(f, delimiter=";")
for row in reader:
for k, v in row.items():
method, traces = [s.strip() for s in k.split(",")]
data[method][int(traces)].append(int(v))
return data
def transform_results(results, transform):
data = collections.defaultdict(dict)
for method, trace_dict in results.items():
for traces, keyranks in trace_dict.items():
data[traces][method] = transform([int(r) for r in keyranks])
return data
def combine_results(results, labels):
data = collections.defaultdict(dict)
for d, l in zip(results, labels):
for traces, method_dict in d.items():
for k, v in method_dict.items():
data[traces][l + " " + k] = v
return data
def main():
data = combine_results(
[
transform_results(
get_results(path), lambda keyranks: keyranks.count(0) / len(keyranks)
)
for path in [
"results/experiments-1653490681.csv",
"results/experiments-1653495764.csv",
]
],
["Same", "Different"],
)
with open("data/success_rates.csv", "w") as f:
fieldnames = ["Traces"] + list(data[0].keys())
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for k, v in data.items():
v["Traces"] = k
writer.writerow(v)
target = {}
for traces, method_dict in data.items():
for method, sr in method_dict.items():
if sr >= 0.99 and method not in target:
target[method] = traces
for i in ["Same", "Different"]:
for j in ["Sum", "Prod", "Max", "Bit 0"]:
print(f"{i} {j}: {target[i + ' ' + j]}")
if __name__ == "__main__":
main()