Skip to content

FEATURE/Make permutation component independent from linear layer#454

Open
peacker wants to merge 14 commits into
developfrom
feature/permutation-component-not-depending-on-linear-layer
Open

FEATURE/Make permutation component independent from linear layer#454
peacker wants to merge 14 commits into
developfrom
feature/permutation-component-not-depending-on-linear-layer

Conversation

@peacker
Copy link
Copy Markdown
Collaborator

@peacker peacker commented May 7, 2026

The permutation component is now an independent component (not falling back to binary linear layer behavior).
Furthermore, the component accepts a word bit size parameter to apply word-wise permutations.
The underlying modeling is still bit-wise.

@peacker peacker force-pushed the feature/permutation-component-not-depending-on-linear-layer branch from 821eeb1 to 735e323 Compare May 7, 2026 05:40
@peacker peacker marked this pull request as ready for review May 7, 2026 05:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes permutations first-class components (instead of being modeled as a special case of linear_layer) and extends them to support word-wise permutations via a word_size parameter, while still modeling at the bit level across the different constraint backends and code generators.

Changes:

  • Introduces an independent Permutation component with SAT/SMT/CP/MILP/algebraic encodings and vectorized evaluation helpers.
  • Adds word_size support to permutation construction (editor + PermutationCipher) and evaluation (bit/byte generic functions).
  • Updates models, inverse-cipher logic, code generation, and unit tests to recognize permutation components and updated component IDs.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/unit/components/permutation_component_test.py Updates expectations for new permutation component identity/encoding; adds algebraic polynomial test.
tests/unit/ciphers/toys/toy_cipherFOUR_test.py Updates verbose-evaluation transcript to reflect permutation_* component IDs.
tests/unit/ciphers/single_component_ciphers/permutation_cipher_test.py Adds tests for custom permutations and word-wise permutations.
tests/unit/ciphers/permutations/spongent_pi_permutation_test.py Updates expected component ID from linear_layer_* to permutation_*.
tests/unit/ciphers/block_ciphers/twofish_block_cipher_test.py Updates expected component ID from linear_layer_* to permutation_*.
tests/unit/ciphers/block_ciphers/qarmav2_with_mixcolumn_block_cipher_test.py Updates expected component ID from linear_layer_* to permutation_*.
tests/unit/ciphers/block_ciphers/des_exact_key_length_block_cipher_test.py Updates expected component ID from linear_layer_* to permutation_*.
tests/unit/ciphers/block_ciphers/des_block_cipher_test.py Updates expected component ID from linear_layer_* to permutation_*.
claasp/name_mappings.py Adds PERMUTATION_COMPONENT = "permutation" component-type constant.
claasp/editor.py Extends add_permutation_component API/docs to accept word_size; updates example output.
claasp/components/permutation_component.py Reimplements permutation as an independent Component with constraints + codegen helpers.
claasp/ciphers/single_component_ciphers/permutation_cipher.py Adds word_size support and default description behavior for word permutations.
claasp/cipher.py Threads word_size through the Cipher.add_permutation_component wrapper.
claasp/cipher_modules/report.py Adds backward-compat handling for historical show_permuation argument typo; avoids KeyErrors via .get().
claasp/cipher_modules/models/sat/sat_models/sat_xor_differential_model.py Includes permutation components when building SAT XOR-differential models.
claasp/cipher_modules/models/milp/milp_models/milp_xor_differential_model.py Includes permutation components when building MILP XOR-differential models.
claasp/cipher_modules/inverse_cipher.py Treats permutations as invertible and implements inversion by inverting the permutation list.
claasp/cipher_modules/generic_functions.py Adds scalar permutation(...) evaluation helper (bit/word-wise).
claasp/cipher_modules/generic_functions_vectorized_byte.py Adds byte_vector_permutation(...) for byte-vectorized evaluation.
claasp/cipher_modules/generic_functions_vectorized_bit.py Adds bit_vector_permutation(...) and refactors verbosity labels (but introduces a NameError bug).
claasp/cipher_modules/code_generator.py Allows permutation components in generated code and emits permutation(...) calls for non-vectorized evaluation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread claasp/cipher_modules/generic_functions_vectorized_bit.py
Comment on lines +34 to +38
For ``word_size=1`` this means ``output[permutation_description[i]] = input[i]``.

When ``word_size=1`` (default), this is a plain bitwise permutation where each entry in
``permutation_description`` is a source *bit* index. When ``word_size > 1``, each entry is
a source *word* index and the description has ``output_bit_size // word_size`` elements.
Comment on lines +99 to +103
perm = self.description[0]
w = self.description[1]
src_to_dst = [perm[j // w] * w + (j % w) for j in range(self.output_bit_size)]
dst_to_src = [0] * self.output_bit_size
for src, dst in enumerate(src_to_dst):
Comment thread claasp/editor.py
Comment on lines +761 to +762
each entry is a source bit index. When ``word_size > 1``, each entry is a source word index and
the list has ``output_bit_size // word_size`` entries.
Comment on lines +18 to +20
# Permutation [3, 2, 1, 0]: output bit i = input bit perm[i]
# Output bit 0 = input bit 3, output bit 1 = input bit 2, etc.
# Input 0b1000 (bit 0=1, rest=0 in MSB-first indexing):
Comment on lines 34 to +38
if permutation_description is None:
permutation_description = list(reversed(range(bit_size)))
if word_size == 1:
permutation_description = list(reversed(range(bit_size)))
else:
n_words = bit_size // word_size
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 9, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants