Skip to content

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

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

Roman Lutz (romanlutz) wants to merge 2 commits 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 <[email protected]>

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.

# Conflicts:
#	pyrit/scenario/scenarios/garak/encoding.py
#	tests/unit/scenario/garak/test_encoding.py

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 completed. No blocking concerns remain. This review records source coverage; merging is handled separately.

[P3] inline:4637103031: Supported and unfixed, but re-rated P3 by concrete impact under the deployed rule. The complete root correctly requests synchronization of Base58/Base62 imports, examples and output: Python guide :53-54,89-90 adds them; the full paired notebook blob 4e1218484f7bec8091374c3c7487b63206d1f302 is unchanged from base and lacks both. MyST publishes that notebook. Readers miss demonstrations; they are not given a failing call, an undefined new import use, or a wrong encoded result. Added Python calls have initialized state and valid public APIs, with retained runtime evidence supporting correct conversion. Mandatory synchronization/end-to-end instructions establish a real omission but do not alone establish P2 impact. Existing working examples are not changed by this addition; absent examples alone are P3. Keep this cause open and repairable together with local:DOC-4454-existing-4637103031.

[P3] local:DOC-4454-existing-4637103031: Supported open P3 combines the missing paired Base58/Base62 demonstrations/results and their absent saved modality rows. Independently rechecked both whole exact-head notebooks: blobs 4e1218484f7bec8091374c3c7487b63206d1f302 and ef838be974b34f1ee55875949fe82fca399e5412 equal the diff base and contain neither new name. The saved table at 0_converters.ipynb:74-75 jumps from Base2048Converter to Base64Converter, reducing discoverability and making its 'all available' enumeration incomplete; it does not prescribe a wrong API, encoding result, modality or runnable recipe. Its Python/table code is already paired and calls get_converter_modalities(). Public lazy exports at init.py:174-175,285, text/text class declarations and converter.py:471-508 already supply both entries; hash-verified combined receipt confirms actual registry construction, technique selection and normalizer conversions work. There is no missing runtime registration, broken supported conversion, new failing executable example or lasting architectural mechanism to repair. Therefore the concrete impact matches deployed policy's P3 absent demonstrations/stale generated catalog category, not its P2 failing-guidance/runtime/structural-design categories. Minimal correction remains synchronize the two notebook imports/calls, retain their results and refresh output with the existing modality producer. No manual catalog, artificial overview Python edit, named-leaf removal or duplicate comment. Original root 4637103031 and supported extension 4638767740 already cover this one source cause; publication duplication does not make it fixed or low-value.

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