Commit fca6943a7dfa23c5eff5c9f6bee4a31513ccee77

Authored by Brice Colombier
1 parent f27b2d69ed
Exists in master

Clean imports

Showing 8 changed files with 40 additions and 39 deletions

binary_par.py View file @ fca6943
... ... @@ -2,12 +2,12 @@
2 2 # Laboratoire Hubert Curien
3 3 # 42000 Saint-Etienne - France
4 4 # Contact: b.colombier@univ-st-etienne.fr
5   -# Project: Demonstrator
  5 +# Project: CASCADE
6 6 # File: binary_par.py
7 7 # Date : 2016-10-12
8 8  
9   -import parity as par
10   -import get_parities_from_indices as gpfi
  9 +from parity import parity
  10 +from get_parities_from_indices import get_parities_from_indices
11 11  
12 12  
13 13 def binary_par(reference_response, blocks_to_correct, response_on_board):
14 14  
... ... @@ -27,10 +27,10 @@
27 27 blocks_to_correct_first_half = [x[:int(len(x)/2)] for x in blocks_to_correct]
28 28 blocks_return = []
29 29 ref_rep = []
30   - parities = gpfi.get_parities_from_indices(blocks_to_correct_first_half, response_on_board)
  30 + parities = get_parities_from_indices(blocks_to_correct_first_half, response_on_board)
31 31 if len(blocks_to_correct[0]) > 2:
32 32 for i, j in enumerate(parities):
33   - if par.parity(reference_response[i][:block_size/2], j):
  33 + if parity(reference_response[i][:block_size/2], j):
34 34 # Error is in the first half of the block
35 35 blocks_return.append(blocks_to_correct[i][:block_size/2])
36 36 ref_rep.append(reference_response[i][:block_size/2])
... ... @@ -2,18 +2,18 @@
2 2 # Laboratoire Hubert Curien
3 3 # 42000 Saint-Etienne - France
4 4 # Contact: b.colombier@univ-st-etienne.fr
5   -# Project: Demonstrator
  5 +# Project: CASCADE
6 6 # File: cascade.py
7 7 # Date : 2016-10-12
8 8  
9   -import binary_par as bi_par
10   -import parity as par
11   -import split as split
12   -import get_parities_from_indices as gpfi
13   -import flip_bits as fb
14   -import flatten as fl
15   -import random as rd
16   -import swap_blocks as sb
  9 +from binary_par import binary_par
  10 +from parity import parity
  11 +from split import split
  12 +from get_parities_from_indices import get_parities_from_indices
  13 +from flip_bits import flip_bits
  14 +from flatten import flatten
  15 +from random import shuffle
  16 +from swap_blocks import swap_blocks
17 17  
18 18  
19 19 def cascade(reference_response, error_rate, nb_passes, response_on_board, initial_block_size=0):
20 20  
21 21  
... ... @@ -50,18 +50,18 @@
50 50 print "Pass :", passe, ", block size", block_size
51 51 reference_response_indexed = zip(indices, reference_response)
52 52 if passe > 0:
53   - rd.shuffle(reference_response_indexed)
  53 + shuffle(reference_response_indexed)
54 54 indices, reference_response = [list(i) for i in zip(*reference_response_indexed)]
55 55  
56   - split.split(reference_response, block_size)
57   - split.split(indices, block_size)
58   - parities = gpfi.get_parities_from_indices(indices, response_on_board)
  56 + split(reference_response, block_size)
  57 + split(indices, block_size)
  58 + parities = get_parities_from_indices(indices, response_on_board)
59 59 blocks_to_correct = []
60 60 reference_response_to_correct = []
61 61 for block_index, (reference_response_block, block_parity) in enumerate(zip(reference_response, parities)):
62 62 # Identify the blocks to correct with BINARY
63 63 # They have an odd relative parity
64   - if par.parity(reference_response_block, block_parity):
  64 + if parity(reference_response_block, block_parity):
65 65 if passe > 0:
66 66 odd_parity_blocks.append(indices[block_index])
67 67 reference_response_to_correct.append(reference_response_block)
68 68  
69 69  
70 70  
71 71  
... ... @@ -72,20 +72,20 @@
72 72 if blocks_to_correct:
73 73 # Narrow down to single bit errors
74 74 while len(blocks_to_correct[0]) > 2:
75   - reference_response_to_correct, blocks_to_correct = bi_par.binary_par(reference_response_to_correct, blocks_to_correct, response_on_board)
  75 + reference_response_to_correct, blocks_to_correct = binary_par(reference_response_to_correct, blocks_to_correct, response_on_board)
76 76 # Final BINARY execution where single PUF bits are queried from the board
77   - _, indices_to_flip = bi_par.binary_par(reference_response_to_correct, blocks_to_correct, response_on_board)
  77 + _, indices_to_flip = binary_par(reference_response_to_correct, blocks_to_correct, response_on_board)
78 78 if passe > 0:
79 79 for index_to_flip in indices_to_flip:
80 80 # Move blocks from one group to the other if they contain the bit to flip
81   - sb.swap_blocks(even_parity_blocks, odd_parity_blocks, index_to_flip, block_size_increased, block_size)
  81 + swap_blocks(even_parity_blocks, odd_parity_blocks, index_to_flip, block_size_increased, block_size)
82 82 else:
83 83 even_parity_blocks.extend(indices)
84   - indices = fl.flatten(indices)
85   - reference_response = fl.flatten(reference_response)
  84 + indices = flatten(indices)
  85 + reference_response = flatten(reference_response)
86 86 if blocks_to_correct:
87 87 # Error correction step
88   - fb.flip_bits(reference_response, indices_to_flip, indices)
  88 + flip_bits(reference_response, indices_to_flip, indices)
89 89 print str(len(indices_to_flip)), "errors corrected before backtracking"
90 90 indices_to_flip = []
91 91 blocks_to_correct = []
92 92  
93 93  
94 94  
... ... @@ -96,14 +96,14 @@
96 96 block_to_correct = min(odd_parity_blocks, key=len) # Get the smallest block
97 97 reference_response_block = [reference_response[indices.index(x)] for x in block_to_correct]
98 98 while len(block_to_correct) > 2:
99   - [reference_response_block], [block_to_correct] = bi_par.binary_par([reference_response_block], [block_to_correct], response_on_board)
  99 + [reference_response_block], [block_to_correct] = binary_par([reference_response_block], [block_to_correct], response_on_board)
100 100 # Final BINARY execution where single PUF bits are queried from the board
101   - _, backtracked_pos = bi_par.binary_par([reference_response_block], [block_to_correct], response_on_board)
  101 + _, backtracked_pos = binary_par([reference_response_block], [block_to_correct], response_on_board)
102 102 # backtracked_pos = bi.binary(reference_response_block, block_to_correct, response_on_board)
103   - fb.flip_bits(reference_response, backtracked_pos, indices)
  103 + flip_bits(reference_response, backtracked_pos, indices)
104 104 print "One more error corrected during backtracking"
105 105 # Move blocks from one group to the other if they contain the bit to flip
106   - sb.swap_blocks(even_parity_blocks, odd_parity_blocks, backtracked_pos[0])
  106 + swap_blocks(even_parity_blocks, odd_parity_blocks, backtracked_pos[0])
107 107 if [x for x in even_parity_blocks if x in odd_parity_blocks]:
108 108 raise ValueError("Blocks are simultaneously in the even and odd group")
109 109 # Un-shuffle
... ... @@ -2,11 +2,11 @@
2 2 # Laboratoire Hubert Curien
3 3 # 42000 Saint-Etienne - France
4 4 # Contact: b.colombier@univ-st-etienne.fr
5   -# Project: Demonstrator
  5 +# Project: CASCADE
6 6 # File: flatten.py
7 7 # Date : 2016-10-12
8 8  
9   -import itertools as it
  9 +from itertools import chain
10 10  
11 11  
12 12 def flatten(liste):
13 13  
... ... @@ -17,6 +17,9 @@
17 17 [1, 2, 3, 4]
18 18 """
19 19  
20   - liste = list(it.chain.from_iterable(liste))
  20 + liste = list(chain.from_iterable(liste))
21 21 return liste
  22 +
  23 +if __name__ == "__main__":
  24 + print flatten([[0, 1, 2, 3], [4, 5, 6, 7]])
flip_bits.py View file @ fca6943
... ... @@ -2,7 +2,7 @@
2 2 # Laboratoire Hubert Curien
3 3 # 42000 Saint-Etienne - France
4 4 # Contact: b.colombier@univ-st-etienne.fr
5   -# Project: Demonstrator
  5 +# Project: CASCADE
6 6 # File: flip_bits.py
7 7 # Date : 2016-10-12
8 8  
get_parities_from_indices.py View file @ fca6943
... ... @@ -2,11 +2,9 @@
2 2 # Laboratoire Hubert Curien
3 3 # 42000 Saint-Etienne - France
4 4 # Contact: b.colombier@univ-st-etienne.fr
5   -# Project: Demonstrator
  5 +# Project: CASCADE
6 6 # File: get_parities_from_indices.py
7 7 # Date : 2016-10-12
8   -
9   -import Tkinter
10 8  
11 9 def get_parities_from_indices(indices, response_on_board):
12 10  
... ... @@ -2,7 +2,7 @@
2 2 # Laboratoire Hubert Curien
3 3 # 42000 Saint-Etienne - France
4 4 # Contact: b.colombier@univ-st-etienne.fr
5   -# Project: Demonstrator
  5 +# Project: CASCADE
6 6 # File: parity.py
7 7 # Date : 2016-10-12
8 8  
... ... @@ -2,7 +2,7 @@
2 2 # Laboratoire Hubert Curien
3 3 # 42000 Saint-Etienne - France
4 4 # Contact: b.colombier@univ-st-etienne.fr
5   -# Project: Demonstrator
  5 +# Project: CASCADE
6 6 # File: split.py
7 7 # Date : 2016-10-12
8 8  
swap_blocks.py View file @ fca6943
... ... @@ -2,7 +2,7 @@
2 2 # Laboratoire Hubert Curien
3 3 # 42000 Saint-Etienne - France
4 4 # Contact: b.colombier@univ-st-etienne.fr
5   -# Project: Demonstrator
  5 +# Project: CASCADE
6 6 # File: swap_blocks.py
7 7 # Date : 2016-10-12
8 8