Skip to content

FEAT: Add BifidConverter (Delastelle Bifid cipher) - #4309

Open
Roman Lutz (romanlutz) wants to merge 4 commits into
microsoft:mainfrom
romanlutz:claude/g1-bifid-f839f2
Open

Roman Lutz (romanlutz) wants to merge 4 commits into
microsoft:mainfrom
romanlutz:claude/g1-bifid-f839f2

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

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; configurable key keyword (non-letters/duplicates ignored, J→I); configurable fractionation period (default 0 = 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 an ALL-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 (key BGWKZQPNDSIOAXEFCLUMTHYVR, FLEEATONCE → UAEOLWRINS), period-block behavior, J-merge, non-letter stripping, letter-free-key equivalence, and identifier params.

Source / references

  • Wikipedia, "Bifid cipher" (public-domain classical cipher)
  • Youliang Yuan et al., "GPT-4 Is Too Smart To Be Safe: Stealthy Chat with LLMs via Cipher" (CipherChat), arXiv:2308.06463

Both cited in the class docstring.

Testing

  • pytest tests/unit/converter/test_bifid_converter.py → 13 passed
  • pre-commit (ruff format, ruff check, ty type check, etc.) → all pass

🤖 Generated with Claude Code

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]>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 08:08

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 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 bifid to 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 varunj-msft 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.

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]>

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.

3 participants