DualCodeDetect: Zero-Shot LLM-Generated Code Detection via Dual-Channel Perturbation
Zhengdao Li, Xiuwei Shang, Zhenkan Fu, Shikai Guo, Weiming Zhang, Nenghai Yu, Kejiang Chen
Abstract
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.
Ask about this paper
Ask your agent about it.
Lune has read the top-tier papers around this one, so every answer names the papers it rests on.
Your agent calls
Lunesearch_papers
Free to start. No credit card required.
Terminal
Install the CLIlune papers get f0b60cf8-5394-4806-bb6e-888540e8da4eRelated papers
- Uncovering LLM-Generated Code: A Zero-Shot Synthetic Code Detector via Code RewritingTong Ye, Yangkai Du, Tengfei Ma, Lingfei Wu et al.AAAI 2025 · 21 citations
- Between Lines of Code: Unraveling the Distinct Patterns of Machine and Human ProgrammersYuling Shi, Hongyu Zhang, Chengcheng Wan, Xiaodong GuICSE 2025 · 9 citations
- Zero-Shot Detection of LLM-Generated Text using Temperature SensitivityShixuan Ma, Jiahao Li, Zhendong Mao, Quan WangACL 2026
- DNA-DetectLLM: Unveiling AI-Generated Text via a DNA-Inspired Mutation-Repair ParadigmXiaowei Zhu, Yubing Ren, Fang Fang, Qingfeng Tan et al.NeurIPS 2025 · 10 citations
- Zero-Shot Detection of LLM-Generated Text using Token CohesivenessShixuan Ma, Quan WangEMNLP 2024 · 5 citations
