DeSoCoRe: Detecting Source Code Re-Use across Programming Languages

Enrique Flores, Alberto Barrón-Cedeño, Paolo Rosso, Lidia Moreno

Introduction

In academic and professional software development, source code plagiarism remains a persistent challenge. While many tools effectively identify copies within a single language (monolingual detection), they often fail when code is "ported" or translated from one language to another—for instance, from Java to C++. Traditional cross-language detection methods frequently rely on comparing intermediate compiler outputs like bytecode. However, these approaches are inherently limited by their dependence on specific compilers and versions.

DeSoCoRe (Detecting Source Code Re-Use) addresses this gap by treating source code as a form of natural language. By employing character n-gram analysis, it offers a language-independent framework capable of identifying suspicious similarities at the function level without requiring compilation.

System Architecture

The DeSoCoRe system is structured into a three-stage pipeline designed to transform raw source files into a curated list of suspicious code pairs.

The three-stage architecture of the DeSoCoRe system, moving from raw code to selected similar pairs.
  1. Source Code Splitter: Using syntactic analyzers, the system decomposes source files into individual functions or methods. It currently supports Python and the "C-syntax family," including C, C++, Java, and C#.
  2. Similarity Estimator: This core component treats code as text. It first strips whitespace and converts text to lowercase. It then extracts character 3-grams (sequences of three characters) and calculates the cosine similarity between these profiles using normalized term frequency ($tf$). This "fuzzy" matching is robust against common obfuscation techniques like variable renaming.
  3. Pair Selector: Finally, the system filters these results, flagging only those function pairs that exceed a predefined similarity threshold (typically 0.8 for C-family languages).

Methodology and Insights

The fundamental insight behind DeSoCoRe is that programming languages can be analyzed as strings of symbols rather than complex Abstract Syntax Trees (ASTs). This simplification allows the tool to remain effective even when logic is slightly restructured or identifiers are changed. For example, if a variable name is changed from counter to i, the majority of the 3-grams in the surrounding logic remain identical, preserving a high similarity score.

To evaluate the system, the authors reference Faidhi and Robinson’s Plagiarism Spectrum (1987), which categorizes program modifications into seven levels, ranging from simple verbatim copying to complex changes in control logic. DeSoCoRe is specifically designed to catch re-use that persists through these various levels of modification.

Visualizing Plagiarism

Beyond providing numerical similarity scores, DeSoCoRe includes a graphical interface powered by the Prefuse Library. This interface represents programs as graphs where nodes are functions and edges represent similarity.

The DeSoCoRe graphical interface visualizing function-level similarities and providing side-by-side code comparison.

As shown in the visualization, this approach allows reviewers to quickly identify the scope of re-use. A cluster of connected nodes suggests that an entire module or architecture may have been borrowed, rather than just a single isolated function. The tool also provides side-by-side code views to facilitate manual verification by an instructor or reviewer.

Conclusion and Future Directions

DeSoCoRe demonstrates that an NLP-based approach to source code analysis is a viable and flexible alternative to compiler-dependent plagiarism detection. While currently focused on the function level for C-family languages and Python, future work aims to increase granularity to the fragment level. This would allow the system to detect smaller snippets of borrowed code embedded within larger, original functions, as well as identify re-use across broader groups of functions.

Summary updated

BibTeX
@inproceedings{flores2012desocore,
  author = {Enrique Flores and Alberto Barrón-Cedeño and Paolo Rosso and Lidia Moreno},
  title = {{DeSoCoRe: Detecting Source Code Re-Use across Programming Languages}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2012},
}
Figure