Skip to main content

superred-optimizer-code-chameleon

A CodeChameleon jailbreak optimizer for the superred red-teaming framework.

Community port — not an official implementation. This module is an unofficial re-implementation of CodeChameleon (Lv et al.) for superred. It is not affiliated with, endorsed by, or maintained by the original authors. See ASSUMPTIONS.md for every deliberate deviation from the paper and reference code.

CodeChameleon hides the unsafe request by encrypting it, then hands the target a matching decryption function and asks it to complete a ProblemSolver class. Because the harmful text never appears in plain form, the target's refusal training — trained on plain English — tends to miss it, and a capable model decrypts and answers inside the code-completion frame.

Reference: Lv et al., "CodeChameleon: Personalized Encryption Framework for Jailbreaking Large Language Models," arXiv:2402.16717 (Feb 2024). Official implementation: huizhang-L/CodeChameleon. See ASSUMPTIONS.md for the full paper-to-code mapping and every deliberate departure.

Install

pip install superred-optimizer-code-chameleon

Usage

from code_chameleon_optimizer import CodeChameleonOptimizer

# Default: one attempt with the `binary_tree` rule and the code-style template
# (the official README example, and the strongest average rule in the paper).
optimizer = CodeChameleonOptimizer()

# Stage several official encryption rules, one per run.
optimizer = CodeChameleonOptimizer(encrypt_rules=["reverse", "odd_even", "length"])

Wire it into a Controller like any other superred optimizer — see the framework's architecture overview and a target's README (e.g. superred-target-chatbot) for a full Controller.run() example.

License

MIT for this port's code (see LICENSE). The upstream reference implementation, huizhang-L/CodeChameleon, is MIT licensed. The prompt templates, encryption rules, and judge prompt ported from it are credited in NOTICE, and its MIT copyright notice is preserved in LICENSES/CodeChameleon-MIT.txt.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

superred_optimizer_code_chameleon-0.1.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file superred_optimizer_code_chameleon-0.1.0.tar.gz.

File metadata

File hashes

Hashes for superred_optimizer_code_chameleon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aaa7e66b07c074f00d961928ecbdf67ddf9eb3bb473bf875988bca9062f1aec5
MD5 880cb8aa2f55fe6996239cc0bd3d11b3
BLAKE2b-256 2af1444f3872d386338db311853e6593f840c5f01f84bc2f3b4d0ce5e9d9a82a

See more details on using hashes here.

Provenance

The following attestation bundles were made for superred_optimizer_code_chameleon-0.1.0.tar.gz:

Publisher: release.yml on RoldSI/superred-modules

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file superred_optimizer_code_chameleon-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for superred_optimizer_code_chameleon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0400b5c65f927ed395253e993a52cd86087b1a0d047b8dea85c387b901b71299
MD5 a4adb21c68596db4f2349efadb9cb1d5
BLAKE2b-256 8a3b02431a4c25fdc9d4b6556630c3b102341611dc8225d94d7e438e5e3a1ed8

See more details on using hashes here.

Provenance

The following attestation bundles were made for superred_optimizer_code_chameleon-0.1.0-py3-none-any.whl:

Publisher: release.yml on RoldSI/superred-modules

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page