{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/codechameleon-personalized-encryption","title":"CodeChameleon: Personalized Encryption Framework for Jailbreaking Large Language Models","arxiv_id":"2402.16717","date":"2024-02-26","proceeding":null,"authors":["Huijie Lv","Xiao Wang","Yuansen Zhang","Caishuang Huang","Shihan Dou","Junjie Ye","Tao Gui","Qi Zhang","Xuanjing Huang"],"abstract":"Adversarial misuse, particularly through `jailbreaking' that circumvents a model's safety and ethical protocols, poses a significant challenge for Large Language Models (LLMs). This paper delves into the mechanisms behind such successful attacks, introducing a hypothesis for the safety mechanism of aligned LLMs: intent security recognition followed by response generation. Grounded in this hypothesis, we propose CodeChameleon, a novel jailbreak framework based on personalized encryption tactics. To elude the intent security recognition phase, we reformulate tasks into a code completion format, enabling users to encrypt queries using personalized encryption functions. To guarantee response generation functionality, we embed a decryption function within the instructions, which allows the LLM to decrypt and execute the encrypted queries successfully. We conduct extensive experiments on 7 LLMs, achieving state-of-the-art average Attack Success Rate (ASR). Remarkably, our method achieves an 86.6\\% ASR on GPT-4-1106.","url_abs":"https://arxiv.org/abs/2402.16717v1","url_pdf":"https://arxiv.org/pdf/2402.16717v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"codechameleon-personalized-encryption","repo_url":"https://github.com/huizhang-l/codechameleon","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"code-completion","task_name":"Code Completion"},{"task_slug":"response-generation","task_name":"Response Generation"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2402.16717","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.16717"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/huizhang-l/codechameleon","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":5,"unverified":3},"by_repo_kind":{"official":{"samples":8,"ran":5,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"9570e81c8e2b90d2","entry":"complete_format","repo":"huizhang-l/codechameleon","repo_kind":"official","path":"utils.py","file_url":"https://github.com/huizhang-l/codechameleon/blob/HEAD/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9570e81c8e2b90d2"}},{"code_sha256_prefix":"b81b4cbc17547aec","entry":"encrypt_binary_tree","repo":"huizhang-l/codechameleon","repo_kind":"official","path":"encrypt.py","file_url":"https://github.com/huizhang-l/codechameleon/blob/HEAD/encrypt.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b81b4cbc17547aec"}},{"code_sha256_prefix":"326ded8f79444c72","entry":"encrypt_none","repo":"huizhang-l/codechameleon","repo_kind":"official","path":"encrypt.py","file_url":"https://github.com/huizhang-l/codechameleon/blob/HEAD/encrypt.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"326ded8f79444c72"}},{"code_sha256_prefix":"6c55bfcfbdd151a6","entry":"encrypt_reverse","repo":"huizhang-l/codechameleon","repo_kind":"official","path":"encrypt.py","file_url":"https://github.com/huizhang-l/codechameleon/blob/HEAD/encrypt.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6c55bfcfbdd151a6"}},{"code_sha256_prefix":"e86ae4f267426ef4","entry":"set_config","repo":"huizhang-l/codechameleon","repo_kind":"official","path":"attack.py","file_url":"https://github.com/huizhang-l/codechameleon/blob/HEAD/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e86ae4f267426ef4"}},{"code_sha256_prefix":"a86d9cb32e713b8f","entry":"get_chat_prompts","repo":"huizhang-l/codechameleon","repo_kind":"official","path":"gpt_evaluate.py","file_url":"https://github.com/huizhang-l/codechameleon/blob/HEAD/gpt_evaluate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a86d9cb32e713b8f"}},{"code_sha256_prefix":"52f2dbe1f1e3b338","entry":"get_data","repo":"huizhang-l/codechameleon","repo_kind":"official","path":"gpt_evaluate.py","file_url":"https://github.com/huizhang-l/codechameleon/blob/HEAD/gpt_evaluate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"52f2dbe1f1e3b338"}},{"code_sha256_prefix":"feb0bd8023992b6f","entry":"get_eval_prompts","repo":"huizhang-l/codechameleon","repo_kind":"official","path":"gpt_evaluate.py","file_url":"https://github.com/huizhang-l/codechameleon/blob/HEAD/gpt_evaluate.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"feb0bd8023992b6f"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}