Why Layered Code Plagiarism Detection Works for CS Departments

The Limits of Single-Technique Detection

For over two decades, code plagiarism detection in higher education relied on one dominant technique: pairwise structural comparison. Tools like MOSS (Measure Of Software Similarity) and JPlag tokenized student submissions and compared them against each other to flag suspiciously similar code. This approach caught the classic "rename variables and reorder functions" plagiarism pattern with reasonable accuracy.

But the threat landscape has shifted. Students now have access to three distinct sources of code that evade traditional pairwise detection: web repositories like GitHub and Stack Overflow, AI-generated code from tools like ChatGPT and GitHub Copilot, and collaborative sharing networks outside institutional boundaries. Each source produces code that looks structurally unique but fails the originality test.

A single detection technique is a single point of failure. The departments that hold the line on academic integrity are those that deploy multiple detection layers.

Each layer uncovers a different category of violation that the others miss, which is why they work best together.

Layer One: Structural Pairwise Comparison

The foundational layer remains pairwise structural analysis. This technique converts source code into normalized token streams that discard superficial differences like whitespace, variable names, and comment text while preserving control flow and algorithmic structure. Two submissions that tokenize differently but produce similar token sequences are likely related.

Consider this common evasion pattern. A student submits:

def sort_list(arr):
    n = len(arr)
    for i in range(n):
        for j in range(0, n-i-1):
            if arr[j] > arr[j+1]:
                arr[j], arr[j+1] = arr[j+1], arr[j]
    return arr

A classmate submits what looks like a different implementation:

def bubble_sort(data):
    length = len(data)
    for outer in range(length):
        for inner in range(0, length-outer-1):
            if data[inner] > data[inner+1]:
                data[inner], data[inner+1] = data[inner+1], data[inner]
    return data

To a human reader, these look different, renamed function, different variable names, reordered loops. To a token-based analyzer, they produce nearly identical token sequences. The structural fingerprint is the same. MOSS and Codequiry both handle this case well.

The limitation: pairwise comparison cannot catch code copied from outside the class. If both students independently copied from the same Stack Overflow answer or GitHub repository, the detector flags them for copying from each other when in fact neither wrote the original. This is where the second layer becomes essential.

Layer Two: Web-Source Code Matching

The second detection layer compares student code against a massive index of publicly available source code. This includes Stack Overflow answers, GitHub repositories, tutorial sites, and academic code archives. The technique uses a combination of code fingerprinting (hashing normalized code fragments) and subsequence matching (finding long common substrings in tokenized code).

Here is the pattern web-source matching catches that pairwise comparison misses. A student copies this answer from a Stack Overflow thread on "how to reverse a linked list in Java":

public ListNode reverseList(ListNode head) {
    ListNode prev = null;
    ListNode current = head;
    while (current != null) {
        ListNode next = current.next;
        current.next = prev;
        prev = current;
        current = next;
    }
    return prev;
}

No other student in the class submitted the same code, so pairwise comparison finds nothing. But the web-source layer matches the tokenized signature against the Stack Overflow code index and flags the submission as a close match to a known public snippet. The student cannot credibly claim they wrote it independently, the structural signature is too precise.

Codequiry's web-source check compares submissions against indexed public repositories and knowledge bases, returning a similarity percentage and a link to the source. This gives instructors immediate evidence rather than a vague suspicion.

The limitation: Web-source matching cannot detect code that was generated by an AI model. LLMs produce code that is structurally original, it does not exist in any training data corpus verbatim. A student who pastes "write a Java method to find the maximum subarray sum" into ChatGPT and submits the output will not trigger web-source matching. This requires a third, fundamentally different detection technique.

Layer Three: AI-Generated Code Detection

The third and newest layer analyzes submissions for statistical patterns characteristic of large language model output. These patterns differ from human-written code in several measurable ways that current tools can identify.

Detectors look for signals such as these:

  • Uniform comment density: AI models tend to comment at a consistent rate. Human-written code is far more variable, depending on the programmer's habits and the assignment's requirements.
  • Predictable identifier lengths: LLMs tend to favor descriptive names within a narrow range. Humans mix very short and very long identifiers far more freely.
  • Structural regularity: AI-generated code tends to follow tidy, conventional structure. Human programmers produce more uneven code, with ad hoc conditionals, nested loops and error handling.

These signals are combined into a confidence score. Codequiry's AI detection layer, for example, returns a probability estimate between 0 and 100 that instructors read alongside the other signals.

The limitation: No AI detector is perfect. False positives happen. Students who write extremely clean, well-commented code that happens to match the LLM pattern will occasionally be flagged. The responsible approach is to treat AI detection as a screening tool, not a conviction mechanism. Flagged submissions require human review, a conversation with the student, a request to explain their code line by line, a comparison with their previous work.

Integration and Workflow Design

The value of layered detection comes from integration, not from running three separate checks. A unified system that reports all three similarity scores in a single dashboard transforms the instructor's workflow. Instead of running MOSS, then separately checking suspicious submissions against web sources, then running a third tool for AI detection, the instructor sees everything at once.

Codequiry's platform presents a consolidated originality report for each submission. The report shows:

  • A pairwise similarity score (comparison against all other class submissions)
  • A web-source similarity score (comparison against public code indexes)
  • An AI-generation probability score
  • A per-line annotation highlighting specific regions flagged by each detector

This design matters because the three detection layers have different false-positive profiles. Pairwise comparison is the most reliable, false positives are rare when the threshold is set at 80% or higher. Web-source matching requires careful calibration; common algorithmic patterns (like standard sorting algorithms or Tree traversal) will match public code even when the student wrote them honestly. AI detection has the highest false-positive rate and requires the most human judgment.

Setting Appropriate Thresholds Per Layer

Different assignments require different detection thresholds. A introductory Python assignment that asks students to implement FizzBuzz will naturally produce code that looks similar across the class, there are only so many ways to write a modulo loop. A senior-level operating systems assignment on virtual memory management should show more variation.

Experienced departments calibrate their thresholds based on assignment type and course level. Here is an illustrative configuration (example values, not measured results):

Course Level Assignment Type Pairwise Threshold Web-Source Threshold AI Detection Threshold
CS 101 Simple algorithm 85% 60% 80%
CS 101 Design project 75% 50% 70%
CS 300+ Data structures 80% 55% 75%
CS 400+ Systems programming 70% 45% 65%

The web-source threshold is deliberately lower than pairwise because matching a public snippet is a weaker signal of misconduct, the student might have legitimately found the same algorithmic solution. The AI detection threshold is higher because false positives are more damaging in that layer. Adjustment is an ongoing process, and a calibration review once per semester is a sensible habit.

Educating Students About the Detection System

The most effective academic integrity systems are transparent about their operation. When students know that submissions are checked against all three detection layers, copying becomes a worse bet, and fewer are tempted to try.

The transparency message works best when framed as an educational tool, not a surveillance system. "We check your code for originality because we want to ensure that you develop the independent problem-solving skills your degree certifies" is more effective than "We will catch you if you cheat." Students who understand the purpose of detection are less likely to view it as adversarial.

A syllabus statement along these lines illustrates the approach:

All programming submissions in this course are checked for originality against three sources: other students' submissions, public code on the internet, and patterns characteristic of code generated by AI tools. This process is designed to protect the value of your degree and ensure that every student's grade reflects their own work. If you have questions about what constitutes acceptable code reuse, ask before the deadline, not after.

The Practical Case for Layered Detection

Adopting layered detection requires investment, both financial and in terms of faculty training. Many departments already use MOSS or JPlag at no cost, and adding web-source matching and AI detection layers means adopting a commercial platform or building custom tooling. For smaller departments, the cost may be a barrier.

But the alternative is an integrity system that misses a growing portion of violations. Code copied from web sources or generated by AI tools never shows up in a pairwise comparison, however carefully the threshold is tuned.

A detection system that catches classmate copying but misses web and AI sources is not a detection system. It is an illusion of oversight. Layered detection closes that gap. It is not perfect, no detection system ever is, but it transforms the coverage from partial to substantial.

Codequiry provides one integrated solution that covers all three layers, with a unified dashboard and per-assignment threshold configuration. For departments currently running separate tools or relying solely on pairwise comparison, the move to layered detection is becoming less of a luxury and more of a standard practice.

The departments that adopt this approach are not doing it because they believe cheating has become an existential crisis. They are doing it because the available detection techniques have matured to the point where layered coverage is achievable and practical. A decade ago, web-source matching was slow and imprecise. AI detection did not exist. Today, both layers are production-ready, and the cost per student is low enough that any department with a reasonable integrity budget can deploy them.

That is the shift worth watching: from single-layer detection to layered detection, driven not by panic but by the maturation of the tools themselves.