Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pyrit/scenario/scenarios/garak/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@
from pyrit.scenario.core.scenario_technique import ScenarioTechnique
from pyrit.score import DecodingScorer, TrueFalseScorer

# Baconian cipher (Francis Bacon, 1605): each letter maps to a 5-symbol a/b group; see
# https://en.wikipedia.org/wiki/Bacon%27s_cipher . Framing classical ciphers as an LLM jailbreak
# vector: CipherChat (Yuan et al., 2023, arXiv:2308.06463).
# Kept as a Leetspeak substitution table rather than a dedicated converter (reuse and compose
# before adding).
_BACONIAN_SUBSTITUTIONS: dict[str, list[str]] = {
"a": ["aaaaa"],
"b": ["aaaab"],
"c": ["aaaba"],
"d": ["aaabb"],
"e": ["aabaa"],
"f": ["aabab"],
"g": ["aabba"],
"h": ["aabbb"],
"i": ["abaaa"],
"j": ["abaaa"],
"k": ["abaab"],
"l": ["ababa"],
"m": ["ababb"],
"n": ["abbaa"],
"o": ["abbab"],
"p": ["abbba"],
"q": ["abbbb"],
"r": ["baaaa"],
"s": ["baaab"],
"t": ["baaba"],
"u": ["baabb"],
"v": ["baabb"],
"w": ["babaa"],
"x": ["babab"],
"y": ["babba"],
"z": ["babbb"],
}


class EncodingDatasetConfiguration(DatasetAttackConfiguration):
"""
Expand Down Expand Up @@ -129,6 +163,7 @@ class EncodingTechnique(ScenarioTechnique):
AsciiSmuggler = ("ascii_smuggler", set[str]())
Bifid = ("bifid", set[str]())
ColumnarTransposition = ("columnar_transposition", set[str]())
Baconian = ("baconian", set[str]())

@classmethod
def get_aggregate_tags(cls) -> set[str]:
Expand Down Expand Up @@ -317,6 +352,7 @@ def _converter_variants() -> list[tuple[list[Converter], str, str]]:
([AsciiSmugglerConverter()], "ascii_smuggler", "ascii_smuggler"),
([BifidConverter()], "bifid", "bifid"),
([ColumnarTranspositionConverter(key="ZEBRAS")], "columnar_transposition", "columnar_transposition"),
([LeetspeakConverter(custom_substitutions=_BACONIAN_SUBSTITUTIONS)], "baconian", "baconian"),
]

# These are the same as Garak encoding attacks
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/scenario/garak/test_baconian_technique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from pyrit.converter import LeetspeakConverter
from pyrit.scenario.scenarios.garak.encoding import _BACONIAN_SUBSTITUTIONS


async def test_baconian_technique_encodes_letters():
"""The baconian Encoding technique is a LeetspeakConverter configured with the Baconian a/b table."""
converter = LeetspeakConverter(custom_substitutions=_BACONIAN_SUBSTITUTIONS)
result = await converter.convert_async(prompt="ab")
assert result.output_text == _BACONIAN_SUBSTITUTIONS["a"][0] + _BACONIAN_SUBSTITUTIONS["b"][0]
3 changes: 2 additions & 1 deletion tests/unit/scenario/garak/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,14 @@ def test_default_aggregate_curates_representative_subset(self):
}
all_names = {t.value for t in EncodingTechnique.get_all_techniques()}
assert default_names < all_names
assert len(all_names) == 19
assert len(all_names) == 20
# The niche/lossy schemes stay ALL-only.
assert all_names - default_names == {
"braille",
"ecoji",
"zalgo",
"ascii_smuggler",
"baconian",
"bifid",
"columnar_transposition",
}
Expand Down
Loading