Repository navigation
fix: correct sign in Unfe odd-round subtraction - #21
Merged
Mzack9999 merged 1 commit intoAug 3, 2026
Merged
Conversation
Mzack9999
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
UnShuffledoes not invertShuffle. Since that round-trip is the whole pointof the package, the reverse direction is effectively unusable today.
(seed 0; same picture on seeds 1 and 42)
Cause
blackrock.go:91, in the odd-round branch ofUnfe:The double negation adds
Rinstead of subtracting it, so the subsequenta - (tmp % a)wrap starts from the wrong value. The even-round branch a fewlines below already does it correctly (
tmp = (tmp - R)), which makes the typoeasy to confirm by symmetry.
Shuffleis unaffected — it remains a valid permutation both before and afterthis change. Only the inverse was broken.
Fix
One character:
Tests
The existing suite only covered
New(), so nothing exercised the cipher itselfand the bug passed CI green. Added:
TestShuffleUnShuffleRoundTrip—UnShuffle(Shuffle(i)) == iacross 6 rangesx 4 seeds, from
range=1up to6,300,000,000TestShuffleIsPermutation— full domain, no duplicates, no values outside[0, Range)TestUnfeInvertsFe—Unfe ∘ Fe == idfor 1, 2 and 3 rounds; each paritytakes a different branch of the reverse construction, so testing only the
default round count hides an error in one of them
TestUnfeSubtractsRoundOutput— targeted regression on the fixed line; itfails if no input reaches the
F(j, L, seed) > Rbranch, so the coveragecannot rot silently
Verified the tests actually catch the bug: reverting the one-character fix makes
three of the four fail. With the fix,
go test ./...andgo vetare clean, andan exhaustive sweep over every range from 1 to 3000 x 4 seeds (18,006,000 checks)
reports zero failures.
Note
gofmt -lflags both files, but that is pre-existing onmain— the repo storesthem with CRLF line endings. With
\rstripped both are clean. I kept CRLF in theadded lines so the source diff stays at one line instead of rewriting the file;
Closes #20