From f2269141be6de189116de554106ee043b6bd0939 Mon Sep 17 00:00:00 2001 From: simopez Date: Thu, 19 Sep 2024 11:55:03 +0200 Subject: [PATCH] FIX/Fix: xor linear model output issue --- .../models/cp/mzn_models/mzn_xor_linear_model.py | 2 +- .../models/cp/mzn_models/mzn_xor_linear_model_test.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/claasp/cipher_modules/models/cp/mzn_models/mzn_xor_linear_model.py b/claasp/cipher_modules/models/cp/mzn_models/mzn_xor_linear_model.py index edf1091b..e5aa4b16 100644 --- a/claasp/cipher_modules/models/cp/mzn_models/mzn_xor_linear_model.py +++ b/claasp/cipher_modules/models/cp/mzn_models/mzn_xor_linear_model.py @@ -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) diff --git a/tests/unit/cipher_modules/models/cp/mzn_models/mzn_xor_linear_model_test.py b/tests/unit/cipher_modules/models/cp/mzn_models/mzn_xor_linear_model_test.py index 10f60b73..d159ea7f 100644 --- a/tests/unit/cipher_modules/models/cp/mzn_models/mzn_xor_linear_model_test.py +++ b/tests/unit/cipher_modules/models/cp/mzn_models/mzn_xor_linear_model_test.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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'