Skip to content

Commit

Permalink
FIX/Fix: xor linear model output issue
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoPez committed Sep 19, 2024
1 parent c967002 commit f226914
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def final_xor_linear_constraints(self, weight):
f'\"{component.id}_o = \"++ show({component.id}_o)++ \"\\n\" ++ ' \
f'show(p[{self.component_and_probability[component.id]}]) ++ \"\\n\" ++'
elif CIPHER_OUTPUT in component.type:
new_constraint += f'\"{component.id}_o= \"++ ' \
new_constraint += f'\"{component.id}_o = \"++ ' \
f'show({component.id}_i)++ \"\\n\" ++ \"0\" ++ \"\\n\" ++'
elif WORD_OPERATION in component.type:
new_constraint = self.get_word_operation_final_xor_linear_constraints(component, new_constraint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_final_xor_linear_constraints():
def test_find_all_xor_linear_trails_with_fixed_weight():
speck = SpeckBlockCipher(block_bit_size=8, key_bit_size=16, number_of_rounds=3)
mzn = MznXorLinearModel(speck)
trails = mzn.find_all_xor_linear_trails_with_fixed_weight(1, solve_external=True)
trails = mzn.find_all_xor_linear_trails_with_fixed_weight(1, solve_external=False)

assert len(trails) == 12

Expand All @@ -36,7 +36,7 @@ def test_find_all_xor_linear_trails_with_fixed_weight():
def test_find_all_xor_linear_trails_with_weight_at_most():
speck = SpeckBlockCipher(block_bit_size=8, key_bit_size=16, number_of_rounds=3)
mzn = MznXorLinearModel(speck)
trails = mzn.find_all_xor_linear_trails_with_weight_at_most(0, 1, solve_external=True)
trails = mzn.find_all_xor_linear_trails_with_weight_at_most(0, 1, solve_external=False)

assert len(trails) == 13

Expand All @@ -48,7 +48,7 @@ def test_find_all_xor_linear_trails_with_weight_at_most():
def test_find_lowest_weight_xor_linear_trail():
speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, number_of_rounds=4)
mzn = MznXorLinearModel(speck)
trail = mzn.find_lowest_weight_xor_linear_trail(solve_external=True)
trail = mzn.find_lowest_weight_xor_linear_trail(solve_external=False)

assert str(trail['cipher']) == 'speck_p32_k64_o32_r4'
assert eval('0x' + trail['components_values']['cipher_output_3_12_o']['value']) >= 0
Expand All @@ -64,7 +64,7 @@ def test_find_lowest_weight_xor_linear_trail():
def test_find_one_xor_linear_trail():
speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, number_of_rounds=4)
mzn = MznXorLinearModel(speck)
trail = mzn.find_one_xor_linear_trail(solve_external=True)
trail = mzn.find_one_xor_linear_trail(solve_external=False)

assert str(trail['cipher']) == 'speck_p32_k64_o32_r4'
assert trail['components_values']['plaintext']['weight'] == 0
Expand All @@ -84,7 +84,7 @@ def test_find_one_xor_linear_trail():
def test_find_one_xor_linear_trail_with_fixed_weight():
speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, number_of_rounds=4)
mzn = MznXorLinearModel(speck)
trail = mzn.find_one_xor_linear_trail_with_fixed_weight(3, solve_external=True)
trail = mzn.find_one_xor_linear_trail_with_fixed_weight(3, solve_external=False)

assert str(trail['cipher']) == 'speck_p32_k64_o32_r4'
assert trail['model_type'] == 'xor_linear_one_solution'
Expand Down

0 comments on commit f226914

Please sign in to comment.