๐ง AI Source Code LeaksApril 3, 2026โ
Tests passing
AI Code Watermarker
AI Code Watermarker embeds invisible but detectable watermarks across source code files to trace code leaks. This tool is especially useful for companies distributing proprietary AI models and code to ensure accountability in case of unauthorized sharing.
What It Does
- Embed invisible watermarks using comments.
- Generate unique watermarks based on identifiers.
- Process individual files or entire directories.
- Configurable output directory.
Installation
pip install pygments==2.15.1Usage
Example Command
python ai_code_watermarker.py --input ./source_code --output ./watermarked_code --identifier "unique_identifier"Arguments
--input: Path to the input file or directory containing source code.--output: Path to the output directory where watermarked files will be saved.--identifier: Unique identifier for generating the watermark.
Source Code
import os
import argparse
import hashlib
from pygments import highlight
from pygments.lexers import guess_lexer_for_filename
from pygments.formatters import HtmlFormatter
def embed_watermark(content, watermark):
"""
Embed a watermark into the source code by appending it as a comment.
"""
watermark_comment = f"# Watermark: {watermark}"
return f"{content}\n{watermark_comment}"
def generate_watermark(identifier):
"""
Generate a unique watermark using a hash of the identifier.
"""
return hashlib.sha256(identifier.encode()).hexdigest()
def process_file(file_path, output_dir, watermark):
"""
Process a single file to embed a watermark.
"""
try:
with open(file_path, 'r') as f:
content = f.read()
watermarked_content = embed_watermark(content, watermark)
output_path = os.path.join(output_dir, os.path.basename(file_path))
with open(output_path, 'w') as f:
f.write(watermarked_content)
print(f"Watermarked file saved to {output_path}")
except Exception as e:
print(f"Error processing file {file_path}: {e}")
def process_directory(input_dir, output_dir, watermark):
"""
Process all files in a directory to embed watermarks.
"""
for root, _, files in os.walk(input_dir):
for file in files:
file_path = os.path.join(root, file)
process_file(file_path, output_dir, watermark)
def main():
parser = argparse.ArgumentParser(description="AI Code Watermarker embeds invisible watermarks in source code files.")
parser.add_argument('--input', required=True, help="Input file or directory containing source code.")
parser.add_argument('--output', required=True, help="Output directory for watermarked source code.")
parser.add_argument('--identifier', required=True, help="Unique identifier for generating the watermark.")
args = parser.parse_args()
input_path = args.input
output_dir = args.output
identifier = args.identifier
watermark = generate_watermark(identifier)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
if os.path.isfile(input_path):
process_file(input_path, output_dir, watermark)
elif os.path.isdir(input_path):
process_directory(input_path, output_dir, watermark)
else:
print("Invalid input path. Please provide a valid file or directory.")
if __name__ == "__main__":
main()
Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- ai_code_watermarker
- Category
- AI Source Code Leaks
- Generated
- April 3, 2026
- Tests
- Passing โ
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-04-03/ai_code_watermarker cd generated_tools/2026-04-03/ai_code_watermarker pip install -r requirements.txt 2>/dev/null || true python ai_code_watermarker.py