1
- from scalib .metrics import SNR , Ttest
1
+ from scalib .metrics import SNR
2
2
from scalib .modeling import LDAClassifier
3
3
from scalib .attacks import FactorGraph , BPState
4
4
from scalib .postprocessing import rank_accuracy
@@ -39,7 +39,7 @@ def main():
39
39
x [:, i ] = labels_p [f"x{ i } " ]
40
40
41
41
# estimate SNR
42
- snr = SNR (nc = nc , ns = ns , np = 16 )
42
+ snr = SNR (nc = nc )
43
43
snr .fit_u (traces_p , x )
44
44
snr_val = snr .get_snr ()
45
45
@@ -53,8 +53,11 @@ def main():
53
53
print (" 3.1 Build LDAClassifier for each xi" )
54
54
models = []
55
55
for i in range (16 ):
56
- lda = LDAClassifier (nc = nc , ns = npoi , p = 1 )
57
- lda .fit_u (l = traces_p [:, pois [i ]], x = labels_p [f"x{ i } " ].astype (np .uint16 ))
56
+ lda = LDAClassifier (nc = nc , p = 1 )
57
+ lda .fit_u (
58
+ traces = np .ascontiguousarray (traces_p [:, pois [i ]]),
59
+ x = labels_p [f"x{ i } " ].astype (np .uint16 ),
60
+ )
58
61
lda .solve ()
59
62
models .append (lda )
60
63
@@ -113,7 +116,7 @@ def main():
113
116
distribution = bp .get_distribution (f"k{ i } " )
114
117
115
118
guess_key .append (np .argmax (distribution ))
116
- ranks .append (256 - np . where (np .argsort (distribution ) == sk )[0 ])
119
+ ranks .append (256 - (np .argsort (distribution ) == sk ). nonzero ()[ 0 ] [0 ])
117
120
118
121
secret_key .append (sk )
119
122
key_distribution .append (distribution )
@@ -124,7 +127,7 @@ def main():
124
127
print (" key byte ranks :" , " " .join (["%3d" % (x ) for x in ranks ]))
125
128
print ("" )
126
129
127
- print (f " 5.2 Estimate full log2 key rank:" )
130
+ print (" 5.2 Estimate full log2 key rank:" )
128
131
key_distribution = np .array (key_distribution )
129
132
130
133
# Scores are negative log-likelihoods.
@@ -139,4 +142,5 @@ def main():
139
142
140
143
141
144
if __name__ == "__main__" :
145
+ print ("attack" )
142
146
main ()
0 commit comments