Hy there,
For those who will face the same problem, here is the solution.
First I had to determine the list of prefixes of the 100 segments (each segment contains a set of power traces). Then, I had to modify the add_trace() method a bit.
import scipy.io
import numpy as np
from os import walk
class native_to_matlab(object):
def __init__(self):
self.tracedata = None
self.textin = None
self.textout = None
self.key = None
def add_trace(self, prefix):
_tracedata = np.load(prefix + '_traces.npy')
_textin = np.load(prefix + '_textin.npy')
_textout = np.load(prefix + '_textout.npy')
_key = np.load(prefix + '_keylist.npy')
if self.tracedata is None:
self.tracedata = _tracedata
self.textin = _textin
self.textout = _textout
self.key = _key
else:
self.tracedata = np.append(self.tracedata, _tracedata, axis=0)
self.textin = np.append(self.textin, _textin, axis=0)
self.textout = np.append(self.textout, _textout, axis=0)
self.key = np.append(self.key, _key, axis=0)
def write_matlab(self, fname):
scipy.io.savemat(fname, {
"traces33": self.tracedata,
"textin33": self.textin,
"textout33": self.textout,
"key33": self.key
})
n2m = native_to_matlab()
prefix_list = []
mypath = r’C:\Users…\Traces Template Attack\TmpTraces_RandPT_RandKey_20000_seg100_1_data\traces\’
f = []
for (dirpath, dirnames, filenames) in walk(mypath):
f.extend(filenames)
break
for filen in f:
# print(filen)
filen_split = filen.split("_")
if filen_split[1] == “keylist.npy”:
prefix_list.append(filen_split[0])
print("prefix list is of size: " + str(len(prefix_list)))
for i, prefix in enumerate(prefix_list):
n2m.add_trace(mypath + prefix)
n2m.write_matlab(‘test_5.mat’)