Commit cb669b45e9c5a3d0805e0218376f818ec1287d8c

Authored by Brice COLOMBIER
1 parent 2ee75dc0f3
Exists in master

Improve README

Showing 5 changed files with 76 additions and 18 deletions

... ... @@ -6,4 +6,5 @@
6 6 *.pyc
7 7 flymd.*
8 8 test*.*
  9 +*.png
... ... @@ -4,22 +4,59 @@
4 4  
5 5 The following preprocessing scripts are available:
6 6  
  7 +* **downsample**
  8 +
  9 + Reduce the size of the traces by keeping only every n<sup>th</sup> sample in the trace starting at a specified offset.
  10 +
  11 +* **filter\_highest\_variance**
  12 +
  13 + Identify points of interest in the trace by keeping only a ratio of the samples with the highest variance.
  14 +
  15 +* **group_process**
  16 +
  17 + Apply the same function to multiples trace files.
  18 +
  19 +* **merge**
  20 +
  21 + Merge multiple trace files into one.
  22 +
  23 +* **npy\_to\_bin**
  24 +
  25 + Convert *.npy* file into *.bin*.
  26 +
7 27 * **pairwise_operation**
8 28  
9   - This script combines pairs of samples.
  29 + Combine pairs of samples.
10 30 The possible pairs of samples are taken inside a sliding window over the trace.
11 31 The operation used to combine the samples can be chosen.
12 32 Thanks to Python `multiprocessing` package, the trace is split into blocks that are processed in parallel.
13 33  
14 34 Combining pairs of samples allows to launch a first-order CPA on a first-order masked implementation, which would otherwise require a second-order CPA.
15 35  
16   -* **downsample**
  36 +* **plot**
17 37  
18   - This script allows to reduce the size of the traces by keeping only every n<sup>th</sup> sample in the trace starting at a specified offset.
19   -
20   -* **filter\_highest\_variance**
  38 + Plot the *n* first traces from a traces file.
21 39  
22   - This script allows to identify points of interest in the trace by keeping only a ratio of the samples with the highest variance.
  40 +* **realign**
  41 +
  42 + Realigns the traces in a file against a reference trace from this file.
  43 +
  44 +* **remove_window**
  45 +
  46 + Remove a window from the traces.
  47 +
  48 +* **shorten**
  49 +
  50 + Shorten the traces by removing the head and/or the tail.
  51 +
  52 +* **split**
  53 +
  54 + Split a traces file into multiple files.
  55 +
  56 +* **step_average**
  57 +
  58 + Group samples from a trace into chunks and compute the mean for each chunk.
  59 + **This is not a moving average**.
23 60  
24 61 ## Install
25 62  
pairwise_operation.py View file @ cb669b4
... ... @@ -80,7 +80,7 @@
80 80 preprocessed_trace[current_index,:] = np.transpose(value)[:,0]
81 81 indexes[current_index] = (start_index+current_start_index, start_index+current_start_index+current_distance)
82 82 # Increase the running index
83   - if current_index in [10350, 20466, 10364, 19934, 10378, 19948, 10392, 19962]:
  83 + if current_index in [16290, 17685, 16304, 16436, 16318, 16450, 16332, 16464]:
84 84 print current_index
85 85 print current_start_index
86 86 print current_distance
1 1 import numpy as np
2 2 import matplotlib.pyplot as plt
  3 +import matplotlib.patches as patches
3 4 import argparse
4 5  
5   -def plot(traces_file):
  6 +def plot(traces_file, nb_subplots):
6 7 traces = np.load(traces_file)
7   - f, axarr = plt.subplots(10, sharex=True)
8   - for i in range(10):
9   - axarr[i].plot((traces[i,:]))
10   - plt.grid()
  8 + points_of_interest = [(21, 66),
  9 + (35, 66),
  10 + (49, 66),
  11 + (63, 66),
  12 + (167, 66),
  13 + (181, 66),
  14 + (195, 66),
  15 + (153, 72)]
  16 + colors = {66:'#1250D2',
  17 + 72:'#C21637'}
  18 + if nb_subplots>1:
  19 + f, axarr = plt.subplots(nb_subplots, sharex=True)
  20 + for i in range(nb_subplots):
  21 + axarr[i].plot((traces[i,:]), color='#666666')
  22 + elif nb_subplots == 1:
  23 + plt.plot(traces[0,:], zorder=-1, color='#666666')
  24 + plt.scatter([poi[0] for poi in points_of_interest], [traces[0,poi[0]] for poi in points_of_interest], color='green', zorder=1)
  25 + plt.scatter([poi[0]+poi[1] for poi in points_of_interest], [traces[0,poi[0]+poi[1]] for poi in points_of_interest], color='red', zorder=1)
  26 + for poi in points_of_interest:
  27 + a = patches.FancyArrowPatch((poi[0],traces[0,poi[0]]), (poi[0]+poi[1],traces[0,poi[0]+poi[1]]), connectionstyle="arc3,rad=1", color=colors[poi[1]], arrowstyle=patches.ArrowStyle("Fancy, head_length=6, head_width=6, tail_width=1"))
  28 + plt.gca().add_patch(a)
11 29 plt.show()
12 30  
13 31 if __name__ == "__main__":
14 32  
... ... @@ -15,6 +33,7 @@
15 33 # Parsing arguments
16 34 parser = argparse.ArgumentParser(description='Preprocess traces')
17 35 parser.add_argument("traces_file", type=str)
  36 + parser.add_argument("-n", "--nb_subplots", type=int)
18 37 args = parser.parse_args()
19   - plot(args.traces_file)
  38 + plot(args.traces_file, args.nb_subplots)
... ... @@ -4,17 +4,18 @@
4 4  
5 5 import matplotlib.pyplot as plt
6 6  
7   -def realign(traces_file):
  7 +def realign(traces_file, ref_trace_index=0):
8 8 traces = np.load(traces_file)
9 9 realigned_traces = np.zeros(np.shape(traces))
10   - ref_trace = traces[0]
  10 + ref_trace = traces[ref_trace_index]
11 11 print np.shape(ref_trace)
12 12 nb_traces = np.shape(traces)[0]
13 13 nb_samples = np.shape(traces)[1]
14 14 realigned_traces[0] = ref_trace
15   - for i in range(1, nb_traces):
16   - shift = np.argmax(np.correlate(ref_trace, traces[i], mode="full")) - nb_samples
17   - realigned_traces[i] = np.roll(traces[i,:], shift)
  15 + for i in range(nb_traces):
  16 + if i != ref_trace_index:
  17 + shift = np.argmax(np.correlate(ref_trace, traces[i], mode="full")) - nb_samples
  18 + realigned_traces[i] = np.roll(traces[i,:], shift)
18 19 dirname, filename = os.path.split(args.traces_file)
19 20 np.save(os.path.join(dirname, "realigned_"+filename), realigned_traces)
20 21