Leveraging Large Language Models to Obscure Code Stylometry: A Comparative Study of GPT-3.5 and GPT-4
This study evaluates the effectiveness of GPT-3.5 and GPT-4 in obscuring code stylometry to evade authorship attribution classifiers, revealing that multi-shot prompting and detailed instructions significantly enhance stylistic obfuscation while highlighting the inherent challenges in preserving code functionality during such modifications.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are a detective trying to identify a suspect not by their face, but by their handwriting. In the world of computer programming, this "handwriting" is called code stylometry. Every programmer has unique habits: how they space their lines, the names they give their variables, and the specific way they structure their logic. Just like a detective can match a note to a suspect, cybersecurity experts use these digital fingerprints to figure out who wrote a piece of software, which is crucial for catching the authors of malicious programs.
However, a new player has entered the game: Large Language Models (LLMs) like GPT-3.5 and GPT-4. Think of these AI models as incredibly talented ghostwriters. They can read a piece of code, understand exactly what it does, and then rewrite it from scratch using a completely different "handwriting" while keeping the machine's instructions identical.
This research paper is essentially a test to see how good these AI ghostwriters are at hiding the original author's identity without breaking the code.
The Experiment: A "Style Swap" Challenge
The researchers set up a competition with two main teams:
- The Detectives: A computer program (a Random Forest classifier) trained to recognize the unique "handwriting" of different programmers.
- The Ghostwriters: The AI models (GPT-3.5 and GPT-4) trying to disguise the code.
The researchers gave the AI 10 different pieces of Java code and asked it to rewrite them using four different strategies:
- The "Just Do It" Approach: A simple command: "Change the style of this code."
- The "Impersonator" Approach: "Rewrite this code to look like it was written by [Famous Programmer X] or from [Specific Region]."
- The "Copycat" Approach: "Here is an example of a specific style; rewrite the code to match this example."
- The "Translator" Approach: "Translate this Java code into C++, then translate it back to Java." The idea is that the translation process forces the AI to make new stylistic choices.
They tested these strategies using two methods:
- Single-Shot: Asking the AI to do the whole job in one go.
- Multi-Shot: Breaking the task down into small, step-by-step instructions (e.g., "First analyze the code, then list changes, then rewrite").
The Results: Who Won the Game?
1. The AI Got Better at Hiding
The study found that the AI models were surprisingly good at changing the "handwriting."
- GPT-4 was the better ghostwriter: It generally did a better job of hiding the original author's identity than GPT-3.5.
- Step-by-step instructions worked best: When the researchers gave the AI detailed, multi-step instructions (Multi-Shot), it was much more successful at disguising the code than when they just gave a simple one-line command (Single-Shot). It's like telling a student "Write a story" vs. "First outline the plot, then write the characters, then write the dialogue." The second method yielded better results.
- The "Translator" trick was the strongest: The strategy of translating the code to another language and back (Strategy 4) was the most effective way to scramble the stylistic fingerprints.
2. The "Broken Code" Problem
There was a catch. While the AI was good at changing the style, it wasn't perfect at keeping the code working.
- Imagine asking a ghostwriter to rewrite a novel but keeping the plot exactly the same. Sometimes, they change a character's name so much that the story no longer makes sense.
- In the study, when they tried to run the rewritten code, 41% of it failed to compile (it wouldn't even start). Another 1% started but failed the tests.
- Only 58% of the rewritten code actually worked perfectly.
- Of the code that did work, only 17% successfully fooled the detective program. This means that out of every 100 attempts, only about 10 resulted in code that was both functional and successfully disguised.
The Bottom Line
This paper concludes that while AI models like GPT-4 are powerful tools for altering code styles and can successfully hide an author's identity, they are not yet perfect "invisibility cloaks."
- They need help: They work best when given detailed, step-by-step instructions rather than simple commands.
- They break things: There is a high risk that in the process of changing the style, the AI will accidentally break the code's functionality.
- The cat-and-mouse game continues: As AI gets better at hiding code styles, the "detectives" (cybersecurity tools) will need to get smarter to catch them.
The researchers emphasize that this study is a snapshot of current capabilities. They found that while the AI can obscure the "handwriting," doing so without breaking the "story" (the code's function) remains a significant challenge.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.