Skip to content

FEAT: Add Base58/Base62 converters on a shared encode_base_n helper - #4454

Open
Roman Lutz (romanlutz) wants to merge 1 commit into
microsoft:mainfrom
romanlutz:gap1-base-n
Open

Roman Lutz (romanlutz) wants to merge 1 commit into
microsoft:mainfrom
romanlutz:gap1-base-n

Conversation

@romanlutz

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

Copy link
Copy Markdown
Contributor

Part of the gap-1 converter series (splitting the esoteric cipher / encoder set into per-converter and per-base PRs). This PR introduces a shared base/helper and the converters built on it; CI-validated locally (unit + garak Encoding + identifier-contract tests).

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):

Adds Base58Converter and Base62Converter (pure-Python, no third-party dependency) built on a shared big-integer encode_base_n helper, registered as ALL-only garak Encoding techniques. Base91 stays separate (different bit-buffer algorithm).

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

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 Base58/Base62 additions and corresponding cell output are missing from the paired notebook, violating the requirement to keep the documentation sources synchronized.

1 open issue
What changed in this PR

Adds Base58 and Base62 text encoding to PyRIT’s converter library, sharing a private encoding helper and making both available in the Garak encoding scenario.

Changes:

  • Implements UTF-8 encoding with leading-zero preservation and Bitcoin/Flickr alphabet options for Base58.
  • Adds lazy public exports and opt-in scenario techniques without changing the default technique set.
  • Adds converter tests, updates scenario expectations, and extends the Python documentation examples.
File Description
tests/​unit/​scenario/​garak/​test_encoding.py Updates technique counts and non-default membership.
tests/​unit/​converter/​test_base62_converter.py Tests known vectors, round trips, and input validation.
tests/​unit/​converter/​test_base58_converter.py Tests alphabets, known vectors, validation, and identifiers.
pyrit/​scenario/​scenarios/​garak/​encoding.py Registers Base58 and Base62 as non-default techniques.
pyrit/​converter/​base62_converter.py Implements Base62 text conversion.
pyrit/​converter/​base58_converter.py Implements Base58 conversion with selectable alphabets.
pyrit/​converter/​_base_n.py Provides the shared encoder with leading-zero preservation.
pyrit/​converter/​__init__.py Exposes both converters through lazy exports.
doc/​code/​converters/​1_text_to_text_converters.py Adds examples for both converters.

Review effort: Balanced

Comment on lines +88 to +89
print("Base58:", await Base58Converter().convert_async(prompt=prompt)) # type: ignore
print("Base62:", await Base62Converter().convert_async(prompt=prompt)) # type: ignore

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.

Please also refresh the stored modality table in doc/code/converters/0_converters.ipynb when synchronizing the examples. The table says it lists all available converters, but its output jumps from Base2048Converter to Base64Converter and omits both new encoders. Both classes are exported and declare text input/output, so the existing get_converter_modalities() code already supplies the rows; no manual converter list is needed. .github/instructions/converters.instructions.md:112 requires this reference update. Keep the paired code synchronized and retain the new example and table outputs.

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