Skip to main content
MOSS (Measure of Software Similarity) is a plagiarism detection service provided by Stanford University. It compares source code submissions to identify potential plagiarism.

What is MOSS?

MOSS is an automatic system for determining the similarity of programs. It has been used extensively in programming courses to detect plagiarism by:
  • Comparing student submissions against each other
  • Detecting shared code between assignments
  • Identifying base code that should be ignored
  • Supporting multiple programming languages
Official website: http://theory.stanford.edu/~aiken/moss/

Obtaining a MOSS User ID

Registration

  1. Send an email to [email protected] with the following body:
registeruser
mail [email protected]
  1. Replace [email protected] with your institutional email address
  2. You will receive a reply with:
    • Your MOSS user ID
    • The MOSS Perl script
    • Instructions for use
MOSS registration is typically only available to instructors at educational institutions. Use your institutional email address when registering.

User ID Format

Your MOSS user ID is a numeric value, for example:
987654321
Keep this ID secure and do not share it publicly.

Configuring MOSS

Locate the MOSS Script

The MOSS script is located at:
tester/moss_original

Set User ID

Open the MOSS script and locate line 167:
$userid=MOSS_USER_ID;
Replace MOSS_USER_ID with your actual MOSS user ID:
$userid=987654321;

Make Script Executable

Ensure the MOSS script has execute permissions:
chmod +x tester/moss_original

Verify Configuration

Test the script is properly configured:
./tester/moss_original -l python file1.py file2.py
You should receive a URL to view the results.

MOSS Script Usage

Basic Usage

The general syntax for using MOSS:
moss [-l language] [-d] [-b basefile1] ... [-m #] [-c "string"] file1 file2 file3 ...

Common Options

-l language

Specify the programming language:
moss -l java *.java
Supported languages:
  • c, cc (C/C++)
  • java
  • ml (ML)
  • pascal
  • ada
  • lisp, scheme
  • haskell
  • fortran
  • perl
  • python
  • javascript
  • csharp
  • vb (Visual Basic)
  • matlab
  • mips (Assembly)
  • And many more (see line 157 in the script)

-d (Directory Mode)

Treat submissions by directory:
moss -d assignment1/*/*.c assignment1/*/*.h
Files in the same directory are considered part of the same program.

-b basefile (Base File)

Exclude instructor-provided code from matching:
moss -l python -b skeleton.py student1.py student2.py student3.py
Multiple base files can be specified:
moss -l java -b BaseClass.java -b Helper.java *.java

-m # (Max Matches)

Set maximum occurrences before ignoring a code passage:
moss -l cpp -m 2 *.cpp
Examples:
  • -m 2: Only report code appearing in exactly 2 programs
  • -m 10 (default): Ignore code appearing in more than 10 programs
  • -m 1000000: Report all matches

-c "string" (Comment)

Add a comment to the report:
moss -l java -c "Assignment 3 - Data Structures" *.java

-n # (Number of Results)

Number of matching files to show (default: 250):
moss -l python -n 100 *.py

Example Commands

moss -l python submission1.py submission2.py submission3.py

Testing MOSS Integration

Create Test Files

Create sample files to test MOSS:
test1.py
def hello():
    print("Hello, World!")
    print("This is a test.")

hello()
test2.py
def hello():
    print("Hello, World!")
    print("This is a test.")

hello()

Run MOSS

./tester/moss_original -l python test1.py test2.py

Interpret Results

MOSS will output a URL:
Query submitted.  Waiting for the server's response.
http://moss.stanford.edu/results/123456789
Open this URL in a browser to view:
  • Percentage of matching code
  • Line-by-line comparison
  • Highlighted similarities

Integration with Wecode

Automated MOSS Checking

Wecode can automatically run MOSS checks on submissions. Configure the MOSS integration in your application.

Batch Processing

Process multiple assignments:
#!/bin/bash
for assignment in assignments/*/; do
    echo "Processing $assignment"
    ./tester/moss_original -l python -c "$(basename $assignment)" $assignment/*.py
done

Scheduled Checks

Set up a cron job to run periodic plagiarism checks:
# Run MOSS check every Sunday at 2 AM
0 2 * * 0 /path/to/wecode/scripts/moss_check.sh

File Permissions

Ensure proper permissions for the MOSS script:
# Make executable
chmod +x tester/moss_original

# Verify permissions
ls -l tester/moss_original
Expected output:
-rwxr-xr-x 1 user user 12345 Mar 04 12:00 tester/moss_original

Troubleshooting

Permission Denied

Problem: bash: ./tester/moss_original: Permission denied Solution:
chmod +x tester/moss_original

Invalid User ID

Problem: Error: Invalid userid Solutions:
  1. Verify you’ve replaced MOSS_USER_ID with your actual numeric ID
  2. Check there are no spaces or quotes around the ID
  3. Ensure the ID is numeric only

Connection Failed

Problem: Could not connect to server moss.stanford.edu Solutions:
  1. Check internet connectivity
  2. Verify firewall allows outbound connections to port 7690
  3. Ensure moss.stanford.edu is reachable:
    ping moss.stanford.edu
    

Perl Not Found

Problem: perl: command not found Solution: Install Perl:
sudo apt-get install perl

File Not Found Errors

Problem: File ... does not exist Solutions:
  1. Verify file paths are correct
  2. Use absolute paths if relative paths fail
  3. Check files are readable:
    ls -l file1.py file2.py
    

Best Practices

  1. Base Files: Always use base files to exclude instructor-provided code
  2. Regular Checks: Run MOSS checks periodically, not just at the end of the course
  3. Privacy: Keep MOSS user ID secure and never commit it to version control
  4. Documentation: Document which submissions were flagged for manual review
  5. False Positives: Always manually review matches before making accusations
  6. Language Settings: Use the correct language flag for accurate results
  7. Sensitivity: Adjust -m parameter based on assignment complexity
  8. Comments: Use -c to label reports for future reference

Understanding MOSS Results

Match Percentages

  • 90-100%: Very high similarity, likely plagiarism
  • 70-90%: High similarity, requires investigation
  • 50-70%: Moderate similarity, may be coincidental
  • Below 50%: Low similarity, likely not plagiarism
High similarity does not automatically mean plagiarism. Common algorithms, templates, and legitimate collaboration can produce similar code. Always review results manually.

Line-by-Line Review

MOSS provides:
  • Color-coded matches
  • Side-by-side comparison
  • Line numbers for reference
  • Percentage calculations

Additional Resources

Limitations

  • MOSS is a detection tool, not proof of plagiarism
  • Cannot detect plagiarism from non-submitted sources
  • May miss heavily obfuscated code
  • Requires manual review of results
  • Service availability depends on Stanford’s servers

Build docs developers (and LLMs) love