Repository navigation
FEAT: Add BifidConverter (Delastelle Bifid cipher) - #4309
Open
Roman Lutz (romanlutz) wants to merge 4 commits into
Open
Roman Lutz (romanlutz) wants to merge 4 commits into
Roman Lutz (romanlutz) wants to merge 4 commits into
Conversation
Implements the classical Bifid fractionating cipher as a text converter: a configurable 5x5 Polybius square (I/J merged, optional keyword) with a configurable fractionation period (default: whole message). Non-letters are dropped and input is uppercased. Registered as an ALL-only encoding technique in the garak Encoding scenario. Stdlib only. Includes unit tests with the canonical Wikipedia known-answer vector (FLEEATONCE -> UAEOLWRINS). Sources: Wikipedia "Bifid cipher" and CipherChat (arXiv:2308.06463), both cited in the docstring. Co-Authored-By: Claude Opus 4.8 <[email protected]>
A key containing no letters leaves nothing to seed the Polybius square, so it collapses to the plain-alphabet default (same as passing no key). Adds an explicit test asserting key="123 !?-" encodes identically to the no-key default. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new bifid technique leaves aggregate-test expectations stale, causing test_default_aggregate_curates_representative_subset to fail until the count and ALL-only set are updated.
1 open issue
What changed in this PR
Adds BifidConverter to extend PyRIT’s classical-cipher obfuscation options for evaluating model safety.
Changes:
- Implements the Bifid cipher with configurable keys and block periods, documenting its lossy text normalization.
- Exposes the converter through lazy imports and adds
bifidto the Garak encoding scenario’s ALL-only techniques. - Adds unit tests for known cipher outputs, normalization, validation, and identifiers.
| File | Description |
|---|---|
tests/unit/converter/test_bifid_converter.py |
Adds 13 tests covering cipher behavior and converter contracts. |
pyrit/scenario/scenarios/garak/encoding.py |
Registers Bifid as an ALL-only encoding technique. |
pyrit/converter/bifid_converter.py |
Implements keyed, period-based Bifid text encoding. |
pyrit/converter/__init__.py |
Adds lazy export and type-checking support for BifidConverter. |
Review effort: Balanced
varunj-msft
approved these changes
Nov 16, 2026
varunj-msft
left a comment
Contributor
There was a problem hiding this comment.
Looks like the new converter still needs a mention in the converter notebooks and the 0_converters modality table (test_all_converters_are_documented fails), and the "(17 encodings)" list in doc/scanner/garak.py might want a refresh too.
- Update garak encoding aggregate test: ALL now has 18 techniques and the ALL-only set includes "bifid" (kept out of DEFAULT). - Document BifidConverter in the text-to-text converter notebook so test_all_converters_are_documented passes. - Refresh the "Available techniques" list in doc/scanner/garak.py (17 -> 18, add Bifid). Synced paired notebooks via jupytext. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Roman Lutz (romanlutz)
enabled auto-merge
November 19, 2026 07:02
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.

Summary
Adds
BifidConverter, a text converter implementing Delastelle's classical Bifid cipher — a fractionating substitution cipher that maps each letter to 5×5 Polybius-square coordinates, fractionates them (all rows, then all columns), and re-pairs the coordinate stream into new letters. This mirrors the existing classical-cipher converters (VigenereConverter,MorseConverter,BrailleConverter) and extends PyRIT's cipher-based obfuscation coverage for evaluating LLM safety (CipherChat, arXiv:2308.06463).Details
pyrit/converter/bifid_converter.py— 5×5 Polybius square with I/J merged; configurablekeykeyword (non-letters/duplicates ignored,J→I); configurable fractionationperiod(default0= whole message). Input is uppercased and non-letters are dropped (documented as lossy). Stdlib only — no new dependency.pyrit/converter/__init__.py— lazy export registration.pyrit/scenario/scenarios/garak/encoding.py— registered as anALL-only"bifid"encoding technique (lossy, like Braille).BifidConverter()takes no required args, so it slots cleanly into the scenario's converter variants.tests/unit/converter/test_bifid_converter.py— 13 unit tests, including the canonical Wikipedia known-answer vector (keyBGWKZQPNDSIOAXEFCLUMTHYVR,FLEEATONCE→UAEOLWRINS), period-block behavior, J-merge, non-letter stripping, letter-free-key equivalence, and identifier params.Source / references
Both cited in the class docstring.
Testing
pytest tests/unit/converter/test_bifid_converter.py→ 13 passed🤖 Generated with Claude Code