Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/doctest-workflow' into feat…
Browse files Browse the repository at this point in the history
…/doctest-workflow
  • Loading branch information
elenamsd committed May 21, 2024
2 parents ab72701 + 3c8750d commit 9c642b4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def build_xor_differential_trail_model(self, weight=-1, fixed_variables=[]):
sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, number_of_rounds=4)
sage: cp = CpXorDifferentialModel(speck)
sage: cp.build_xor_differential_trail_model(-1, fixed_variables)
sage: cp.build_xor_differential_trail_model()
"""
self.initialise_model()
self.c = 0
Expand Down Expand Up @@ -338,12 +338,19 @@ def find_lowest_weight_xor_differential_trail(self, fixed_values=[], solver_name
sage: speck = SpeckBlockCipher(number_of_rounds=5)
sage: cp = CpXorDifferentialModel(speck)
sage: cp.find_lowest_weight_xor_differential_trail(solver_name='Chuffed') # random
{'building_time': 0.007165431976318359,
'cipher_id': 'speck_p32_k64_o32_r4',
'components_values': {'cipher_output_4_12': {'value': '850a9520',
'weight': 0},
{'cipher': speck_p32_k64_o32_r5,
'model_type': 'xor_differential_one_solution',
'solver_name': 'Chuffed',
'solving_time_seconds': 120.349,
'memory_megabytes': 0.28,
'components_values': {'plaintext': {'value': '28000010', 'weight': 0},
'key': {'value': '0000000000000000', 'weight': 0},
...
'total_weight': '9.0'}
'cipher_output_4_12': {'value': '850a9520', 'weight': 0.0}},
'total_weight': '9.0',
'status': 'SATISFIABLE',
'building_time_seconds': 0.0021665096282958984,
'test_name': 'find_lowest_weight_xor_differential_trail'}
# related-key setting
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_model import (CpXorDifferentialModel)
Expand Down Expand Up @@ -386,7 +393,7 @@ def find_one_xor_differential_trail(self, fixed_values=[], solver_name=SOLVER_DE
sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialModel(speck)
sage: cp.find_one_xor_differential_trail(solver_name=Chuffed') # random
sage: cp.find_one_xor_differential_trail(solver_name='Chuffed') # random
{'cipher_id': 'speck_p32_k64_o32_r2',
'model_type': 'xor_differential_one_solution',
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def build_xor_differential_trail_second_step_model(self, weight=-1, fixed_variab
EXAMPLES::
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'not_equal', range(128),
....: integer_to_bit_list(0, 128, 'little'))]
sage: cp.build_xor_differential_trail_second_step_model(-1, fixed_variables)
Expand Down Expand Up @@ -98,10 +98,10 @@ def find_all_xor_differential_trails_with_fixed_weight(self, fixed_weight, fixed
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'equal', range(128),
....: integer_to_bit_list(0, 128, 'little'))]
sage: fixed_variables.append(set_fixed_variables('plaintext', 'not_equal', range(128),
Expand Down Expand Up @@ -135,19 +135,20 @@ def find_lowest_weight_xor_differential_trail(self, fixed_values=[], first_step_
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'equal', range(128),
....: integer_to_bit_list(0, 128, 'little'))]
sage: fixed_variables.append(set_fixed_variables('plaintext', 'not_equal', range(128),
....: integer_to_bit_list(0, 128, 'little')))
sage: cp.find_lowest_weight_xor_differential_trail(fixed_variables, 'Chuffed', 'Chuffed') # random
{'cipher_id': 'aes_block_cipher_k128_p128_o128_r2',
5
{'cipher': 'aes_block_cipher_k128_p128_o128_r2',
'model_type': 'xor_differential',
'solver_name': 'Chuffed',
'components_values': {'key': {'value': '0', 'weight': 0},
'components_values': {'key': {'value': '00000000000000000000000000000000', 'weight': 0},
...
'total_weight': '30.0'}
"""
Expand All @@ -170,19 +171,19 @@ def find_one_xor_differential_trail(self, fixed_values=[], first_step_solver_nam
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'equal', range(128),
....: integer_to_bit_list(0, 128, 'little'))]
sage: fixed_variables.append(set_fixed_variables('plaintext', 'not_equal', range(128),
....: integer_to_bit_list(0, 128, 'little')))
sage: cp.find_one_xor_differential_trail(fixed_variables, 'Chuffed', 'Chuffed') # random
{'cipher_id': 'aes_block_cipher_k128_p128_o128_r2',
{'cipher': 'aes_block_cipher_k128_p128_o128_r2',
'model_type': 'xor_differential',
...
'cipher_output_1_32':{'value': 'ffffffffffffffffffffffffffffffff', 'weight': 0}},
'cipher_output_1_32':{'value': 'ffffffffffffffffffffffffffffffff', 'weight': 0.0}},
'total_weight': '224.0'}
"""
return self.solve_full_two_steps_xor_differential_model('xor_differential_one_solution', 0, fixed_values, first_step_solver_name, second_step_solver_name)
Expand All @@ -205,16 +206,16 @@ def find_one_xor_differential_trail_with_fixed_weight(self, fixed_weight=-1, fix
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'equal', range(128),
....: integer_to_bit_list(0, 128, 'little'))]
sage: fixed_variables.append(set_fixed_variables('plaintext', 'not_equal', range(128),
....: integer_to_bit_list(0, 128, 'little')))
sage: cp.find_one_xor_differential_trail_with_fixed_weight(224, fixed_variables, 'Chuffed', 'Chuffed') # random
{'cipher_id': 'aes_block_cipher_k128_p128_o128_r2',
{'cipher': 'aes_block_cipher_k128_p128_o128_r2',
'model_type': 'xor_differential',
'solver_name': 'Chuffed',
...
Expand All @@ -234,16 +235,16 @@ def generate_table_of_solutions(self, solution, solver_name):
EXAMPLES::
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'not_equal', list(range(128)),
....: integer_to_bit_list(0, 128, 'little'))]
sage: cp.build_xor_differential_trail_first_step_model(-1,fixed_variables)
sage: first_step_solution, solve_time = cp.solve_model('xor_differential_first_step', 'Chuffed')
sage: cp.generate_table_of_solutions(first_step_solution)
sage: cp.generate_table_of_solutions(first_step_solution, 'Chuffed')
"""
cipher_name = self.cipher_id
separator = '----------'
Expand Down Expand Up @@ -290,9 +291,9 @@ def input_xor_differential_constraints(self):
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: cp.input_xor_differential_constraints()
(['array[0..127] of var 0..1: key;',
'array[0..127] of var 0..1: plaintext;',
Expand Down Expand Up @@ -326,18 +327,19 @@ def solve_full_two_steps_xor_differential_model(self, model_type='xor_differenti
EXAMPLES::
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'not_equal', list(range(128)),
....: integer_to_bit_list(0, 128, 'little'))]
sage: cp.solve_full_two_steps_xor_differential_model('xor_differential_one_solution', -1, fixed_variables, 'Chuffed', 'Chuffed') # random
{'building_time': 3.7489726543426514,
'cipher_id': 'aes_block_cipher_k128_p128_o128_r2',
1
{'cipher': 'aes_block_cipher_k128_p128_o128_r2',
...
'total_weight': '6'}
'total_weight': '6.0',
'building_time': 3.7489726543426514}
"""
possible_sboxes = 0
if weight > 0:
Expand Down Expand Up @@ -435,11 +437,11 @@ def solve_model(self, model_type, solver_name=None):
EXAMPLES::
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'not_equal', list(range(128)),
....: integer_to_bit_list(0, 128, 'little'))]
sage: cp.build_xor_differential_trail_first_step_model(-1, fixed_variables)
Expand Down Expand Up @@ -508,16 +510,17 @@ def transform_first_step_model(self, attempt, active_sboxes, weight=-1):
EXAMPLES::
sage: from claasp.cipher_modules.models.cp.cp_models.cp_xor_differential_trail_search_fixing_number_of_active_sboxes_model import (
....: CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel)
....: CpXorDifferentialFixingNumberOfActiveSboxesModel)
sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.utils import set_fixed_variables, integer_to_bit_list
sage: aes = AESBlockCipher(number_of_rounds=2)
sage: cp = CpXorDifferentialTrailSearchFixingNumberOfActiveSboxesModel(aes)
sage: cp = CpXorDifferentialFixingNumberOfActiveSboxesModel(aes)
sage: fixed_variables = [set_fixed_variables('key', 'not_equal', range(128),
....: integer_to_bit_list(0, 128, 'little'))]
sage: cp.build_xor_differential_trail_first_step_model(-1, fixed_variables)
sage: first_step_solution, solve_time = cp.solve_model('xor_differential_first_step','Chuffed')
sage: cp.transform_first_step_model(0, first_step_solution[0])
1
"""
print(active_sboxes)
self._first_step_find_all_solutions = []
Expand Down

0 comments on commit 9c642b4

Please sign in to comment.