DualCodeDetect: Zero-Shot LLM-Generated Code Detection via Dual-Channel Perturbation
The rapid advancement of large language models (LLMs) in code generation has greatly improved software development efficiency, but it has also raised concerns about misuse, making the distinction between human-written and LLM-generated code an urgent task. However, existing detection methods for LLM-generated content, particularly perturbation-based zero-shot methods, are primarily designed for natural language scenarios and fail to transfer effectively to the task of detecting generated code. When directly applied to code, they face two major challenges: (1) the low-entropy nature of code restricts the perturbation space and weakens discriminative signals; and (2) prior perturbation methods often compromise semantic integrity or executability, leading to substantial performance degradation. To address these issues, we propose DualCodeDetect, a novel zero-shot detection framework that amplifies the differences between LLM-generated and human-written code through a dual-channel perturbation mechanism. In the semantic channel, we design an identifier perturbation strategy based on outside-nucleus sampling, which disrupts the strong consistency of LLMs in identifier selection. In the structural channel, empirical analysis reveals that LLM-generated code exhibits greater uniformity in stylistic features; leveraging this insight, we construct a rule-based library of semantics-preserving code transformations to introduce structural perturbations that further magnify statistical disparities. In experiments conducted across two datasets and ten representative code LLMs, DualCodeDetect achieves an average AUROC of 0.8477, alongside FPR and FNR values of 0.0430 and 0.0552, respectively, on Python under both T =0.2 and T =1.0 temperature settings with a reasonable runtime overhead. Furthermore, it demonstrates strong cross-language generalization on Java, C++, and JavaScript, confirming its significant superiority over existing detection methods.
Authors
- Shikai Guo (ORCID: https://orcid.org/0000-0002-8554-6365)
- Xiuwei Shang (ORCID: https://orcid.org/0009-0009-6660-9947)
- Kejiang Chen (ORCID: https://orcid.org/0000-0002-9868-3414)
- Nenghai Yu (ORCID: https://orcid.org/0000-0003-4417-9316)
- Weiming Zhang (ORCID: https://orcid.org/0000-0001-5576-6108)
- Zhengdao Li (ORCID: https://orcid.org/0000-0002-1736-8608)
- Zhenkan Fu
Institutions
- University of Science and Technology of China (CN)
- Dalian Maritime University (CN)
Publication Details
- Journal
- Proceedings of the ACM on software engineering.
- Published
- 2026-06-30
- DOI
- https://doi.org/10.1145/3808166
- Primary Topic
- Software Engineering Research
- Type
- article
- Field-Weighted Citation Impact
- 0.00
Funders
- National Natural Science Foundation of China