forked from WhiteboxFiltering/WhiteboxFiltering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepareTraces.py
64 lines (53 loc) · 1.97 KB
/
prepareTraces.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
import argparse
import pathlib
import os
import io
import sys
from transposeTraces import transposeTraces
from RNR import RNR
parser = argparse.ArgumentParser(
description='description to do later',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
'trace_dirs', type=pathlib.Path, nargs='+',
help="1 or more paths to directories with trace/plaintext/ciphertext files"
)
parser.add_argument(
'-W', '--Window', type=int, default=-1,
help="Window Size for Redundant Node Removal"
)
parser.add_argument(
'-S', '--Sliding', type=int, default=-1,
help="Number of nodes to slide after resolving a window for Redundant Node Removal"
)
parser.add_argument(
'-t', '--falsePos', type=int, default=30,
help="Exceding number of traces to avoid false-positives"
)
parser.add_argument(
'--save-relations', action='store_true',
help="Save redundant relations in a pickle file",
)
parser.add_argument(
'--no-affine', action='store_true',
help="Do not remove affine redundancies"
)
args = parser.parse_args()
for trace_dir in args.trace_dirs:
print("Processing trace folder", trace_dir)
transposeTraces(trace_dir)
print()
try:
RNR(trace_dir, args.Window, args.Sliding, args.falsePos, save_relations=args.save_relations)
except Exception as err:
print("Error:", err)
print("The file \"nodeVectors.bin\" is corrupted, most likely because the program has been")
print("interrupted when creating it.")
print("Removing it and recreating a new one...")
#If transposeTraces is interrupted halfway through computation, an unfinished
#nodeVectors.bin file can be created and won't work. This excpetion resolves
#this problem.
os.remove(trace_dir / "nodeVectors.bin")
transposeTraces(trace_dir)
RNR(trace_dir, args.Window, args.Sliding, args.falsePos, affine=not args.no_affine)