Repository navigation
FIX MathObfuscationConverter: write the multiplication explicitly for digits - #4055
Open
barkha1research-ai wants to merge 2 commits into
Open
barkha1research-ai wants to merge 2 commits into
barkha1research-ai wants to merge 2 commits into
Conversation
… digits Signed-off-by: Barkha <340367068+barkha1research-ai@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The test imports MathObfuscationConverter from its implementation module rather than the public package, violating the public-import check and causing a check-public-imports failure.
1 open issue
What changed in this PR
Fixes #4054 by making decimal-digit equations in MathObfuscationConverter valid arithmetic identities while preserving output for non-digit characters.
Changes:
- Uses explicit multiplication for decimal digits and documents the behavior.
- Adds regression tests for ASCII digits, an Arabic-Indic digit, and mixed letter/digit input.
| File | Description |
|---|---|
| tests/unit/converter/test_math_obfuscation_converter.py | Adds digit identity and mixed-input tests; changes the converter import. |
| pyrit/converter/math_obfuscation_converter.py | Adds explicit multiplication for decimal digits and updates the class docstring. |
Review effort: Balanced
Signed-off-by: Barkha <340367068+barkha1research-ai@users.noreply.github.com>
|
|
||
| n = rng.randint(self._min_n, self._max_n) | ||
| line = f"{ch} = {n}{ch} - {n - 1}{ch}" | ||
| multiply = "*" if ch.isdecimal() else "" |
Contributor
There was a problem hiding this comment.
isdecimal misses superscripts, subscripts and fractions, so ² still comes out as ² = 3² - 2² (reads as 9 - 4) and ½ as 3½ - 2½. isnumeric covers those too:
Suggested change
| multiply = "*" if ch.isdecimal() else "" | |
| multiply = "*" if ch.isnumeric() else "" |
pushed it with a test here if you want to cherry pick: its-amann@19e785c
This branch has not been deployed
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.

Description
Fixes #4054.
MathObfuscationConverterwrites each character asX = nX - (n - 1)X. For a digit,nXreads as a two-digit number, so5 = 85 - 75is5 = 10, and every digit gives 10 for anyn. This writes the multiplication out for decimal digits, for example5 = 8*5 - 7*5, and leaves letters and symbols unchanged, so existing output for non-digit text is identical. The class docstring now says so.Tests and Documentation
Added a parametrized test that checks every digit from 0 to 9, and an Arabic-Indic digit, produces a line that matches
d = a*d - b*dand is a true identity, plus a test for a prompt that mixes a letter and a digit. The new digit cases fail onmain.pytest tests/unitpasses apart from onetest_attack_analyticscase that also fails onmain, andruff,tyandpre-commitpass on the changed files.