Skip to content

FIX MathObfuscationConverter: write the multiplication explicitly for digits - #4055

Open
barkha1research-ai wants to merge 2 commits into
microsoft:mainfrom
barkha1research-ai:fix-math-obfuscation-digits
Open

barkha1research-ai wants to merge 2 commits into
microsoft:mainfrom
barkha1research-ai:fix-math-obfuscation-digits

Conversation

@barkha1research-ai

Copy link
Copy Markdown
Contributor

Description

Fixes #4054.

MathObfuscationConverter writes each character as X = nX - (n - 1)X. For a digit, nX reads as a two-digit number, so 5 = 85 - 75 is 5 = 10, and every digit gives 10 for any n. This writes the multiplication out for decimal digits, for example 5 = 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*d and is a true identity, plus a test for a prompt that mixes a letter and a digit. The new digit cases fail on main. pytest tests/unit passes apart from one test_attack_analytics case that also fails on main, and ruff, ty and pre-commit pass on the changed files.

… digits

Signed-off-by: Barkha <340367068+barkha1research-ai@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 8, 2026 03:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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 ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

No deployments
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.

BUG MathObfuscationConverter writes false equations for digits ("5 = 85 - 75")

3 participants