Skip to content
Merged
4 changes: 2 additions & 2 deletions doc/scanner/garak.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@
"pyrit_scan run garak.encoding --target openai_chat --techniques base64 --max-total 1\n",
"```\n",
"\n",
"**Available techniques** (20 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex,\n",
"**Available techniques** (21 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex,\n",
"QuotedPrintable, UUencode, ROT13, Braille, Atbash, MorseCode, NATO, Ecoji, Zalgo, LeetSpeak,\n",
"AsciiSmuggler, Bifid, ColumnarTransposition, UbbiDubbi\n",
"AsciiSmuggler, Bifid, ColumnarTransposition, UbbiDubbi, Disemvowel\n",
"\n",
"**Aggregate techniques:** `ALL` (every encoding, exhaustive) and `DEFAULT` (a broad curated subset\n",
"spanning every encoding family — base-N, byte-encodings, substitution ciphers, and symbolic\n",
Expand Down
4 changes: 2 additions & 2 deletions doc/scanner/garak.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@
# pyrit_scan run garak.encoding --target openai_chat --techniques base64 --max-total 1
# ```
#
# **Available techniques** (20 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex,
# **Available techniques** (21 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex,
# QuotedPrintable, UUencode, ROT13, Braille, Atbash, MorseCode, NATO, Ecoji, Zalgo, LeetSpeak,
# AsciiSmuggler, Bifid, ColumnarTransposition, UbbiDubbi
# AsciiSmuggler, Bifid, ColumnarTransposition, UbbiDubbi, Disemvowel
#
# **Aggregate techniques:** `ALL` (every encoding, exhaustive) and `DEFAULT` (a broad curated subset
# spanning every encoding family — base-N, byte-encodings, substitution ciphers, and symbolic
Expand Down
16 changes: 10 additions & 6 deletions pyrit/scenario/scenarios/garak/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class EncodingTechnique(ScenarioTechnique):
ALL = ("all", {"all"})
DEFAULT = ("default", {"default"})

# Individual encoding techniques (the enum value is the encoding scheme name). Members tagged ``default``
# form the curated DEFAULT aggregate: a broad spread across encoding families so the default scan is a
# meaningful scanner run — base-N (Base64, Base2048, Base16, Base32, ASCII85, Hex), byte-encodings
# (QuotedPrintable, UUencode), substitution ciphers (ROT13, Atbash, LeetSpeak), and symbolic alphabets
# (MorseCode, NATO). The remaining niche/lossy schemes (Braille, Ecoji, Zalgo, AsciiSmuggler) are
# ALL-only.
# Individual encoding techniques (the enum value is the encoding scheme name). Each member's tag set
# drives the aggregates: members tagged ``default`` form the curated DEFAULT aggregate — a broad spread
# across encoding families (base-N, byte-encodings, substitution ciphers, symbolic alphabets) so the
# default scan is meaningful. Members with no ``default`` tag are ALL-only, run only by the exhaustive
# ``ALL`` aggregate (the niche or lossy schemes). The ALL-only set is defined by these tags, not listed
# here, so it stays correct as techniques are added.
Base64 = ("base64", {"default"})
Base2048 = ("base2048", {"default"})
Base16 = ("base16", {"default"})
Expand All @@ -130,6 +130,7 @@ class EncodingTechnique(ScenarioTechnique):
AsciiSmuggler = ("ascii_smuggler", set[str]())
Bifid = ("bifid", set[str]())
ColumnarTransposition = ("columnar_transposition", set[str]())
Disemvowel = ("disemvowel", set[str]())
Comment thread
romanlutz marked this conversation as resolved.
Resolved
UbbiDubbi = ("ubbi_dubbi", set[str]())

@classmethod
Expand Down Expand Up @@ -319,6 +320,9 @@ def _converter_variants() -> list[tuple[list[Converter], str, str]]:
([AsciiSmugglerConverter()], "ascii_smuggler", "ascii_smuggler"),
([BifidConverter()], "bifid", "bifid"),
([ColumnarTranspositionConverter(key="ZEBRAS")], "columnar_transposition", "columnar_transposition"),
# "disemvowel": remove all vowels ("disemvoweling"), a comment-moderation technique
# popularized on the Making Light blog (https://nielsenhayden.com/makinglight/).
([SearchReplaceConverter(pattern="[AEIOUaeiou]", replace="")], "disemvowel", "disemvowel"),
# "ubbi_dubbi": a language game that prefixes each vowel run with "ub", popularized by
# the PBS children's show Zoom (1972). https://en.wikipedia.org/wiki/Ubbi_dubbi
([SearchReplaceConverter(pattern=r"([aeiouAEIOU]+)", replace=r"ub\1")], "ubbi_dubbi", "ubbi_dubbi"),
Expand Down
52 changes: 51 additions & 1 deletion tests/unit/scenario/garak/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,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) == 20
assert len(all_names) == 21
# The niche/lossy schemes stay ALL-only.
assert all_names - default_names == {
"braille",
"ecoji",
"zalgo",
"ascii_smuggler",
"disemvowel",
"ubbi_dubbi",
"bifid",
"columnar_transposition",
Expand Down Expand Up @@ -350,6 +351,55 @@ async def test_base64_trimmed_to_two_variants(
# The trimmed variants must not appear.
assert not any("standard" in n or "b2a" in n for n in names)

async def test_disemvowel_technique_builds_registered_row(
self, mock_objective_target, mock_objective_scorer, mock_attack_seed_groups, mock_dataset_config
):
"""Selecting Disemvowel must register a row whose converter strips vowels.

This exercises the registered ``disemvowel`` row end to end (not a hand-built converter), so a
deleted or misnamed row in ``_converter_variants()`` is caught: such a regression leaves the
enum intact while the technique builds no attacks.
"""
from unittest.mock import patch

with patch.object(
Encoding,
"_resolve_seed_groups_by_dataset_async",
new_callable=AsyncMock,
return_value={"memory": mock_attack_seed_groups},
):
scenario = Encoding(objective_scorer=mock_objective_scorer)
scenario.set_params_from_args(
args={
"objective_target": mock_objective_target,
"dataset_config": mock_dataset_config,
"scenario_techniques": [EncodingTechnique.Disemvowel],
}
)
await scenario.initialize_async()

attacks = scenario._get_converter_attacks(
context=scenario._build_scenario_context(seed_groups_by_dataset={"memory": mock_attack_seed_groups})
)

assert attacks, "disemvowel technique built no attacks"
assert all(aa.display_group == "disemvowel" for aa in attacks)
names = {aa.atomic_attack_name for aa in attacks}
assert "disemvowel_raw" in names, "missing raw variant"
assert any(n != "disemvowel_raw" for n in names), "missing decode variant"

# The registered row's converter actually strips vowels.
raw = next(aa for aa in attacks if aa.atomic_attack_name == "disemvowel_raw")
row_converters = [
conv
for config in raw.attack_technique.attack.get_request_converters()
for conv in config.converters
if isinstance(conv, SearchReplaceConverter)
]
assert row_converters, "disemvowel row applies no SearchReplaceConverter"
result = await row_converters[0].convert_async(prompt="Hello World")
assert result.output_text == "Hll Wrld"

async def test_ubbi_dubbi_technique_builds_registered_row(
self, mock_objective_target, mock_objective_scorer, mock_attack_seed_groups, mock_dataset_config
):
Expand Down
Loading