Skip to content

FEAT: Add PolybiusConverter (polybius converter) - #4443

Open
Roman Lutz (romanlutz) wants to merge 9 commits into
microsoft:mainfrom
romanlutz:gap1-polybius
Open

Roman Lutz (romanlutz) wants to merge 9 commits into
microsoft:mainfrom
romanlutz:gap1-polybius

Conversation

@romanlutz

@romanlutz Roman Lutz (romanlutz) commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds this converter as part of the gap-1 converter series (splitting the esoteric cipher / encoder set into per-converter and per-base PRs). Includes a unit test and garak Encoding-scenario registration; CI-validated locally.

Sibling PRs will be cross-linked once the series is open.

🤖 Generated with Claude Code

gap-1 converter series — splitting the esoteric cipher / encoder set into reviewable PRs (open each independently; they touch the same four registration files, so later ones rebase as earlier ones merge):

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:35

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

Merge-letter validation accepts multi-character entries, allowing invalid grid coordinates or construction-time KeyErrors instead of the documented ValueError.

2 open issues
What changed in this PR

Adds PolybiusConverter to PyRIT’s text-encoding converters and makes it available in the Garak Encoding scenario.

Changes:

  • Implements configurable Polybius-square encoding with merged letters and coordinate separators.
  • Exports the converter and registers it as an ALL-only encoding technique.
  • Adds unit coverage, identifier samples, and a Python documentation example.
File Description
tests/​unit/​scenario/​garak/​test_encoding.py Updates technique counts and ALL-only expectations.
tests/​unit/​registry/​converter_identifier_samples.py Adds custom merge-letter samples for identifier checks.
tests/​unit/​converter/​test_polybius_converter.py Covers encoding, configuration, validation, and identifiers.
pyrit/​scenario/​scenarios/​garak/​encoding.py Registers the Polybius technique and converter variant.
pyrit/​converter/​polybius_converter.py Implements Polybius-square text encoding.
pyrit/​converter/​__init__.py Adds the public lazy export and typing import.
doc/​code/​converters/​1_text_to_text_converters.py Adds a Polybius conversion example.

Review effort: Balanced

Comment thread pyrit/converter/polybius_converter.py Resolved

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.

Automated review of 129744d. I reviewed all changed source and docs. The converter is a welcome named leaf, but two issues should be fixed before merge: word gaps and digits look like coordinate pairs (line 146), and the two separator options have no current need (line 46). The other inline comments are small P3 improvements. I also replied on both earlier Copilot threads. Note: the branch conflicts with main in encoding.py and test_encoding.py, and some comments refer to code that is on main now.

Comment thread pyrit/converter/polybius_converter.py Resolved
Comment thread pyrit/converter/polybius_converter.py Resolved
Comment thread pyrit/converter/polybius_converter.py Outdated

# Build the 5x5 grid from the alphabet with the second merged letter removed, then
# point the removed letter at the cell of the first merged letter.
grid_letters = [letter for letter in _ALPHABET if letter != second]

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.

[P3] Use one owner for the Polybius square

Lines 79-85 build the same 5x5 square (alphabet without J, index // 5, index % 5) that BifidConverter._build_square and its coordinate maps already build. Draft #4458 moves the Bifid square into a shared _polybius_square.py helper, but it does not change this file. If both merge, PyRIT has two square builders with different rules, and they can drift. Move the square and the index-to-coordinate map into one small shared helper that both converters use, in this PR or by adding PolybiusConverter to #4458. Do not call the private Bifid classmethod from this converter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After the WordLevelConverter rewrite the square here is a single 25-letter constant plus a small coordinate map, and I do not call Bifid's private classmethod. Extracting a shared _polybius_square.py now would collide with draft #4458, which already introduces that exact helper for the Bifid square — so per your alternative, this is best folded into #4458 (add PolybiusConverter there) rather than duplicating the helper in this PR. Leaving this thread open for that cross-PR coordination.

Comment thread pyrit/converter/polybius_converter.py Resolved
Resolve garak encoding conflicts take-BOTH (Polybius + Disemvowel/UbbiDubbi);
set ALL technique count to true value 22.

DOC: bump garak technique list to 22 encodings (add Polybius) in
doc/scanner/garak.py and garak.ipynb; regenerate the converter modality
table in doc/code/converters/0_converters.ipynb to include PolybiusConverter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… test

Address review threads: add the Polybius import, example print, and saved
output to doc/code/converters/1_text_to_text_converters.ipynb (paired with
the .py); add test_polybius_technique_builds_registered_row mirroring the
disemvowel/ubbi_dubbi row tests so a lost or misnamed polybius variant row
is caught.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Resolve garak encoding conflicts take-BOTH (Pigpen + Polybius); set the ALL
technique count to the true value 23. Bump the scanner-guide technique list
to 23 encodings (add Polybius alongside Pigpen) in doc/scanner/garak.py and
garak.ipynb. Keep both the polybius and pigpen row-build tests. Regenerate
the converter modality table in doc/code/converters/0_converters.ipynb to
include both PigpenConverter and PolybiusConverter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address review threads on PR microsoft#4443:
- Remove the merge_letters, coordinate_separator, and letter_separator
  options (no callers; options for hypothetical needs, and some values
  produced undecodable output). The merge_letters substring check also
  accepted multi-character/empty entries. I and J now always share one
  cell, like BifidConverter.
- Rebuild on WordLevelConverter (like NatoConverter): each ASCII letter
  encodes to a two-digit pair, tokens are space-separated, and word
  boundaries are written as a '/' token. This keeps word gaps and literal
  digits distinct from coordinate pairs ('AB CD' -> '11 12 / 13 14' vs
  'ABCD' -> '11 12 13 14'; 'A1' != '1A').
- Add to_ascii_equivalent folding J->I (j->i) so the Encoding scenario's
  DecodingScorer accepts correctly-decoded replies for seeds containing J
  (microsoft#4437 hook). Returns None when nothing changes.
- Update converter tests, drop the merge_letters identifier sample, refresh
  the row-build assertion, add a polybius decoded_text scenario test, and
  update the stored notebook example output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

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