Skip to content

Add linear and affine equivalence between two SBoxes#5

Open
NeKroFR wants to merge 1 commit into
PoustouFlan:mainfrom
NeKroFR:LE+AE
Open

Add linear and affine equivalence between two SBoxes#5
NeKroFR wants to merge 1 commit into
PoustouFlan:mainfrom
NeKroFR:LE+AE

Conversation

@NeKroFR
Copy link
Copy Markdown

@NeKroFR NeKroFR commented May 20, 2026

Added linear and affine equivalence between two SBoxes (-eq flag).

linear_equivalence(other) finds invertible matrices $A, B$ such that $S(x) = B \cdot T(A \cdot x)$. affine_equivalence(other) adds the offsets $a, b$ such as $S(x) = B \cdot T(A \cdot x \oplus a) \oplus b$. Both return None if no such matrices exist.

This feature is useful when dealing with obfuscated SBoxes that we suspect to be a disguised version of a known one. For example an SBox extracted from a binary that looks random but might secretly be a standard SBox wrapped in extra linear layers.

Also added a showcase pair in examples: gf16_inv (the $GF(2^4)$ inverse) and mystery, an affine disguise of it. Without the tool, the two look unrelated; with -eq, the hidden structure is recovered.

❯ python main.py -eq -in examples/gf16_inv examples/mystery
examples/gf16_inv vs examples/mystery
Affine equivalent! S(x) = B·T(A·x ⊕ a) ⊕ b, with A, a, B, b:
1 0 0 0           1       0 1 1 1         0
0 1 1 1           1       0 1 0 1         0
0 1 0 1           1       0 0 1 1         1
0 0 1 1           1       1 0 0 1         1

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.

1 participant