Repository navigation
FEAT: Add baconian Encoding technique via LeetspeakConverter - #4445
Roman Lutz (romanlutz) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The converter permits ambiguous encodings with colliding custom symbols and alters unsupported characters instead of preserving them, compromising reversibility and multilingual payload integrity.
2 open issues
What changed in this PR
Adds Baconian cipher encoding to PyRIT’s converter library and makes it available in the Garak Encoding scenario.
Changes:
- Supports classic 24-letter and distinct 26-letter variants with configurable symbols.
- Exports the converter and registers it under
ALL, without changing the default technique set. - Adds converter tests, updates scenario expectations, and adds a Python documentation example.
| File | Description |
|---|---|
tests/unit/scenario/garak/test_encoding.py |
Updates technique counts and verifies Baconian remains outside the default set. |
tests/unit/converter/test_baconian_converter.py |
Tests cipher variants, custom symbols, input handling, and identifier creation. |
pyrit/scenario/scenarios/garak/encoding.py |
Registers the Baconian technique and converter. |
pyrit/converter/baconian_converter.py |
Implements Baconian encoding and configurable alphabets. |
pyrit/converter/__init__.py |
Adds the public lazy export and typing import. |
doc/code/converters/1_text_to_text_converters.py |
Adds a Baconian conversion example. |
Review effort: Balanced
| ValueError: If ``symbol_a`` or ``symbol_b`` is empty, or if they are equal. | ||
| """ | ||
| if not symbol_a or not symbol_b: | ||
| raise ValueError("symbol_a and symbol_b must both be non-empty.") | ||
| if symbol_a == symbol_b: | ||
| raise ValueError("symbol_a and symbol_b must be different.") | ||
|
|
||
| self.distinct_letters = distinct_letters | ||
| self.symbol_a = symbol_a | ||
| self.symbol_b = symbol_b | ||
| self._mapping = self._build_mapping() |
| for char in text.upper(): | ||
| if char in self._mapping: | ||
| tokens.append(self._mapping[char]) |
|
Reworked per the reuse-before-adding guidance: dropped |
005fd13 to
9730d57
Compare
Per review (reuse and compose before adding): keep the baconian technique but implement it as LeetspeakConverter(custom_substitutions=<Baconian a/b table>) instead of a dedicated BaconianConverter class. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
9730d57 to
b3423f5
Compare
| "g": ["aabba"], | ||
| "h": ["aabbb"], | ||
| "i": ["abaaa"], | ||
| "j": ["abaaa"], |
There was a problem hiding this comment.
[P2] Accept a faithful Baconian decode in the scorer
The table maps i and j to "abaaa" and u and v to "baabb". A target that decodes the ciphertext by this table answers "iauascript" for "javascript" and "HAIII" for "Hajji". DecodingScorer does a case-insensitive substring match against the seed, so it scores these answers False. With the default datasets, this occurs for 14 of 17 garak_web_html_js seeds and 5 of 56 garak_slur_terms_en seeds. The run then reports the target as resistant although it decoded and repeated the payload. Main already fixes this class of problem for AsciiSmugglerConverter (#4437): Encoding._seed_groups_for_converters reads a converter's to_ascii_equivalent and stores the result as decoded_text, which DecodingScorer also accepts. When you rebase, keep the canonical table and add a thin BaconianConverter(LeetspeakConverter) that passes this table and exposes that fold (j to i, v to u). Then a faithful decode and a context-repaired decode both score True. Add a test that a j/v seed gets the folded decoded_text.
|
|
||
| async def test_baconian_technique_encodes_letters(): | ||
| """The baconian Encoding technique is a LeetspeakConverter configured with the Baconian a/b table.""" | ||
| converter = LeetspeakConverter(custom_substitutions=_BACONIAN_SUBSTITUTIONS) |
There was a problem hiding this comment.
[P3] Test the registered baconian row, not a hand-built converter
This test builds its own LeetspeakConverter and computes the expected value from the same _BACONIAN_SUBSTITUTIONS constant. If the baconian row is deleted from _converter_variants(), or a table code is wrong, this test and all of test_encoding.py still pass (checked with a mutation run: 33 passed). Selecting EncodingTechnique.Baconian would then build no attacks or wrong ciphertext without an error. Remove this file and add test_baconian_technique_builds_registered_row to test_encoding.py, as main does in test_disemvowel_technique_builds_registered_row: select the technique, build the attacks, take the converter from the baconian_raw attack, and assert a literal output, for example "Hello World" -> "aabbbaabaaababaababaabbab babaaabbabbaaaaababaaaabb".
| AsciiSmuggler = ("ascii_smuggler", set[str]()) | ||
| Bifid = ("bifid", set[str]()) | ||
| ColumnarTransposition = ("columnar_transposition", set[str]()) | ||
| Baconian = ("baconian", set[str]()) |
There was a problem hiding this comment.
[P3] Add Baconian to the Garak scanner guide
doc/scanner/garak.py and doc/scanner/garak.ipynb list every Encoding technique by name in "Available techniques". On main this list now has 21 encodings and ends with "UbbiDubbi, Disemvowel", because #4448 and #4449 updated it. This PR adds Baconian but does not change the guide, so after merge an operator who reads the guide does not find the technique. When you rebase, add Baconian to that line in both files and change the count to 22.

Adds the baconian Encoding technique via an existing converter (reuse before adding):
LeetspeakConverter(custom_substitutions=_BACONIAN_SUBSTITUTIONS), with the Baconian a/b table retained as that constant. Keeps the named technique and a focused test.Baconian — each letter maps to a 5-symbol a/b group. Source: Francis Bacon, 1605 (Wikipedia). Jailbreak framing: CipherChat, Yuan et al., arXiv:2308.06463.
gap-1 converter series: #4441 #4442 #4443 #4444 #4445 #4446 #4447 #4448 #4449 #4450 #4451 #4452 #4454 #4455 #4456 #4457 #4458
🤖 Generated with Claude Code