Two submissions to the same assignment both score 68%. One comes from a student who wrote the code alone and happened to reach for the same textbook loop. The other comes from a student who copied a classmate's file and renamed a dozen variables. The number is identical. The interpretation is not.
That gap between "a number" and "a finding" is where integrity cases go sideways. A code similarity score is a ratio: matched material over some total. Change what counts as material, or change what counts as the total, and the same pair of files can report 30%, 68%, or 94% from three different tools without a single character changing. Knowing the arithmetic is what lets you defend a decision to a student, a department chair, or an appeals committee.
How a code similarity score is calculated
Serious detectors run a similar pipeline. The file goes through a language-aware lexer, so the tool knows an identifier from a string literal from an operator. Then comes normalization: comments and whitespace go away, identifiers get mapped to placeholders, and literals are sometimes abstracted to a type marker. The result is a token stream. That stream is cut into overlapping windows, typically k-grams with k somewhere between 10 and 20, each window is hashed, and a winnowing pass samples the hashes so a document of any length becomes a compact set of fingerprints.
MOSS works this way, following the winnowing scheme described by Schleimer, Wilkerson and Aiken in 2003. JPlag takes a different route toward a related end: greedy string tiling over token streams, which finds long non-overlapping matching runs and reports what fraction of each program those runs cover. Dolos combines k-gram fingerprinting with tree-based comparison. Different mechanisms, same output shape, a percentage.
Every one of those designs measures coverage. Coverage is a property of text, not of intent. And coverage is exquisitely sensitive to how much text there is.
Why short files report higher similarity than long ones
Consider a five-line function written by two students who never met:
def mean(values):
total = 0
for v in values:
total += v
return total / len(values)
There is no other reasonable way to write this at an introductory level. The token streams are identical, so a token-based checker reports close to 100% on the fragment, and if the whole file is twelve lines, the file-level score lands in the same neighborhood. Nothing has happened except that the space of correct solutions to a trivial problem is very small.
Now hand the same tool two 400-line submissions that share a 30-line utility block lifted from a common tutorial. The percentage collapses to single digits even though the copying is real and provable. A similarity percentage is not a measure of wrongdoing; it's a measure of shared surface area relative to file size, and those two things diverge in both directions.
A practical rule of thumb that holds across token-based tools: below roughly 40 significant lines, percentages are noisy and should carry little weight on their own. Past a few hundred lines, the ratio stabilizes and begins to behave like evidence.
Renaming is invisible by design, not by accident
The identifier normalization step is why a rename does nothing to hide plagiarism. These two loops are the same program:
for (int i = 0; i < values.length; i++) {
sum += values[i];
}
for (int idx = 0; idx < arr.length; idx++) {
total += arr[idx];
}
The lexer emits the same token sequence for both, so the hashes match and no amount of renaming helps the copier. This is the correct behavior for catching the lazy case, and it is also the source of the false positive you will see most often: two students who independently wrote the same idiomatic nested loop produce an identical token stream because the language leaves them no alternative. Token normalization buys invariance to renaming and pays for it with invariance to idiom.
What structural comparison adds beyond tokens
Tree-based comparison parses both files into abstract syntax trees and matches subtrees, which survives reordering and some rewriting that token sequences do not. Take these two implementations of the same filter:
def clean(records):
out = []
for r in records:
if r.active:
out.append(r.name.strip().lower())
return out
def clean(records):
return [r.name.strip().lower()
for r in records if r.active]
A token-based matcher sees moderate overlap and reports an ambiguous number. An AST matcher sees that one is a loop with an accumulating list and the other is a comprehension, notes the shared attribute chain and method calls inside, and can tell you exactly which subtrees agree. That detail matters more than the final percentage, because it lets you point at the specific structure rather than wave at a score.
Honest limit: an AST comparison will not call these two identical, because structurally they are not. Refactoring to a comprehension is a genuine rewrite. Subtree matching catches shared fragments inside a rewrite, not the rewrite itself.

Starter code creates a similarity floor for the whole cohort
Most assignments ship with scaffolding. A provided interface, an imports block, a `main` that reads the input file, a skeleton class with four method stubs. If the assignment is 60 lines and 35 of them came from you, then every pair of submissions in the course shares 35 lines, and pairwise similarity starts somewhere around 55% before anyone copies anything.
Two ways to deal with this. The first is to subtract the baseline: run the skeleton against itself, record which matched regions belong to it, and exclude those regions from reported matches. The second, which works better as a grading aid, is to stop looking at absolute scores and rank submissions against the cohort distribution. If the median pair in a class of 200 scores 61%, then a pair at 63% is unremarkable and a pair at 91% is worth thirty minutes of your afternoon. Outlier ranking is the more honest view because it encodes what the assignment actually produces, including whatever you handed out for free.

A worked example of a misleading 70%
Say a course of 200 students submits a 60-line Python assignment. The instructor provided 35 lines of scaffolding. Two submissions each run about 64 lines, and the checker reports 70%. The matched regions break down as: the full skeleton (35 lines), the standard `if __name__ == "__main__":` block (2 lines), a two-line error message string that the assignment statement quotes verbatim, and six lines of an actual helper function.
Sixty-four lines shared minus roughly 39 explained lines leaves about 25 lines of genuine overlap, and of those, six are the interesting ones. Whether that is a case depends on those six lines. If they implement a non-obvious edge case in a distinctive way, you have something. If they are a plain `try/except` around a file read, you have two students who both read the assignment.
Flip the shape and the same number gets stronger. Two submissions of a 12-line hand-written helper that share 8 contiguous lines, with the rest of the file written in visibly different styles, deserve a closer look even though the file-level score is only in the sixties, because the match length relative to the student-authored material is high. Matched span length beats matched percentage as a first filter, every time.
| What changes | Effect on the reported score | Effect on evidential value |
|---|---|---|
| Student-authored file gets longer | Score drops | Rises if the match survives |
| More starter code in the assignment | Score rises | Falls sharply |
| Identifiers renamed | No change | No change |
| Loop rewritten as comprehension | Score drops | Depends on AST overlap |
| Match concentrated in one long block | May be unchanged | Rises sharply |
Why the same threshold cannot serve every course
An intro CS1 assignment in Java has a tiny solution space. Every correct answer to "reverse this array" is four lines long and looks like every other answer, so a threshold of 80% would flag half the class and teach you nothing. Upper-level coursework is the opposite: an operating systems project or a compilers assignment has enormous design freedom, so two submissions at 60% are usually worth reading, because there was no reason for them to converge.
The practical move is to set the review threshold low and the accusation threshold high. Queue anything above the cohort median plus a margin, then spend human attention on the top of the list, reading matched spans rather than percentages. Autograding and enforcement are separate systems and should stay that way.

What the score cannot tell you
Similarity between two submissions has at least four possible causes, and the tool only sees one of them. Independent convergence on idiomatic code is the first. Shared external source is the second: both students pulled the same helper from the same Stack Overflow answer, which is a citation problem rather than a collusion problem, and requires a check against the open web and public repositories to distinguish. A third is pair programming that crossed the line from collaboration into transcription, which is a policy question your syllabus has to answer before the tool can help.
The fourth is generative AI, and it complicates the arithmetic in a specific way. Two students who give the same prompt to the same model get near-identical output, so peer similarity spikes without any student-to-student contact. A peer-only scan will flag them as a collusion pair, which is the wrong finding. The right finding requires a separate signal: an AI code detector that scores likelihood of machine generation per file, layered on top of peer and web results rather than replacing them.
That layering is the reason we built Codequiry the way we did. A check runs three engines on the same submission set: peer similarity using token, AST and fingerprint matching that survives renaming and reformatting; web and GitHub matching against real online sources rather than a closed corpus; and per-file AI generation scoring. You get a source code plagiarism checker and an AI detector in one report instead of two tools with two sets of scores you have to reconcile by hand. It is a commercial alternative to MOSS or JPlag with an actual interface, and if you are already running MOSS in a shell script, the comparison is worth ten minutes.

Reading a report without overreading it
Start with the matched spans, not the score. A 70% built from fourteen fragments of four to six tokens each is noise: common idioms, shared keywords, the language itself. A 70% built from one 200-token block with three smaller satellites is a signal, and you can point at the block. Most tools will show you this if you open the comparison view; the percentage is just the sort key that got you there.
Then check whether the match crosses what the assignment was testing. Two students with identical boilerplate around genuinely different algorithmic cores have not plagiarized the part that mattered. Two students with different boilerplate wrapped around an identical core have.
Last, write down the finding in terms of spans and files. "Submission 41 and 53 share a 47-token block in solve_grid() that matches a helper published in the course textbook, chapter 9" is a statement a student can respond to. "The checker said 84%" is not.
Frequently Asked Questions
What similarity percentage counts as plagiarism?
There is no universal number, and any tool that publishes one is guessing. Scores above roughly 80% on long student-authored files usually merit review; scores in the sixties are common in courses with heavy starter code and mean little on their own. Treat the percentage as a ranking device and the matched span as the evidence.
Why do two students who never spoke get a high similarity score?
Idiomatic code converges. Small problems have small solution spaces, and normalization that strips identifier names makes independently written loops look identical. Check the matched spans: if the overlap sits in short, conventional fragments spread across the file, it is convergence rather than copying.
Does renaming variables or reformatting hide copied code?
No, for any tool that tokenizes. Identifiers and whitespace are normalized before hashing, so renaming changes nothing in the fingerprint set. It works only against naive text diffing, which is not what serious detectors do.
Can two students get a high peer score because they both used ChatGPT?
Yes, and it is one of the more common false collusion signals right now. Shared prompts produce shared output. Run an AI generation score alongside the peer comparison so the report distinguishes "these two talked to each other" from "these two talked to the same model."
If you want to see what the score actually decomposes into on your own assignment set, run a check in the code plagiarism checker and start from the matched spans.