def _one_biconf_iteration(self): self.stats.biconf_iterations += 1 cascade = self._algorithm.biconf_cascade # Randomly select half of the bits in the key. This is exactly the same as doing a new # random shuffle of the key and selecting the first half of newly shuffled key. key_size = self._reconciled_key.get_size() shuffle = Shuffle(key_size, Shuffle.SHUFFLE_RANDOM) mid_index = key_size // 2 chosen_block = Block(self._reconciled_key, shuffle, 0, mid_index, None) if cascade: self._register_block_key_indexes(chosen_block) # Ask Alice what the correct parity of the chosen block is. self._schedule_ask_correct_parity(chosen_block, False) # If the algorithm wants it, also ask Alice what the correct parity of the complementary # block is. if self._algorithm.biconf_correct_complement: complement_block = Block(self._reconciled_key, shuffle, mid_index, key_size, None) if cascade: self._register_block_key_indexes(complement_block) self._schedule_ask_correct_parity(complement_block, False) # Service all pending correction attempts (potentially including Cascaded ones) and ask # parity messages. errors_corrected = self._service_all_pending_work(cascade) return errors_corrected
def test_create_block(): # Block covers entire shuffle. Key.set_random_seed(2221) Shuffle.set_random_seed(2222) key = Key.create_random_key(8) assert key.__repr__() == "Key: 10111010" shuffle = Shuffle(key.get_size(), Shuffle.SHUFFLE_RANDOM) assert shuffle.__repr__( ) == "Shuffle: 0->0 1->1 2->6 3->4 4->3 5->2 6->5 7->7" block = Block(key, shuffle, 3, 6, None) assert block.__repr__() == "Block: 3->4=1 4->3=1 5->2=1" block = Block(key, shuffle, 0, 8, None) assert block.__repr__( ) == "Block: 0->0=1 1->1=0 2->6=1 3->4=1 4->3=1 5->2=1 6->5=0 7->7=0" # Block covers part of the shuffle. block = Block(key, shuffle, 1, 3, None) assert block.__repr__() == "Block: 1->1=0 2->6=1" # Single bit block. block = Block(key, shuffle, 2, 3, None) assert block.__repr__() == "Block: 2->6=1"