forked from WhiteboxFiltering/WhiteboxFiltering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relationsExtract.py
67 lines (49 loc) · 1.9 KB
/
relationsExtract.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
import os
import argparse
import pathlib
import pickle
import fnmatch
from time import time
from tqdm import tqdm
from sage.all import Matrix, GF, floor
from transposeTraces import getHeader, getNodeVectors, writeNodeVectors
def extract_relations(pathToTraces, dstTraces, relFile, NRNfile):
#RECOVERING THE HEADER OF THE NODE VECTORS FILE
(numOfNodes, T) = getHeader(pathToTraces)
dstTraces.mkdir(exist_ok=True)
with open(relFile, "rb") as file:
relations=pickle.load(file)
with open(NRNfile, "rb") as file:
NonRedundantNodes=pickle.load(file)
#NODEVECTORS = getNodeVectors(pathToTraces, T)[0]
NODEVECTORS = getNodeVectors(pathToTraces, T, NonRedundantNodes=NonRedundantNodes)[0]
NODEVECTORS = dict(zip(NonRedundantNodes, NODEVECTORS))
OUTPUT = []
for rel in tqdm(relations):
res = sum(NODEVECTORS[idx] for idx in rel)
OUTPUT.append(res)
print("Writing...")
writeNodeVectors(OUTPUT, dstTraces / "nodeVectors.bin")
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='description to do later',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
'src_trace_dir', type=pathlib.Path,
help="1 or more paths to directories with trace/plaintext/ciphertext files"
)
parser.add_argument(
'dst_trace_dir', type=pathlib.Path,
help="1 or more paths to directories with trace/plaintext/ciphertext files"
)
parser.add_argument(
'rel_file', type=pathlib.Path,
help="1 or more paths to directories with trace/plaintext/ciphertext files"
)
parser.add_argument(
'NRN_file', type=pathlib.Path,
help="1 or more paths to directories with trace/plaintext/ciphertext files"
)
args = parser.parse_args()
extract_relations(args.src_trace_dir, args.dst_trace_dir, args.rel_file, args.NRN_file)