Skip to main content

py-self-md5

py-self-md5 wraps a Python script so the generated script prints MD5: <DIGEST> before running the original program.

The generated script does not read its own source file at runtime. Instead, the inserted prefix stores a quine-style byte template and computes the digest from the reconstructed bytes in memory.

This project is inspired by zhuzilin/pdf-with-its-own-md5, where selectable MD5-collision carriers are used to display the final digest in a PDF. This tool targets executable Python programs and does not require HashClash or precomputed collision blocks.

Install

Requires Python 3.11 or newer.

python -m pip install py-self-md5

After installation, run the built-in check:

py-self-md5 --self-test

You can also run it from the project root without installing:

python -m py_self_md5 --self-test

Usage

Create input.self_md5.py:

py-self-md5 input.py

Run the generated script:

python input.self_md5.py

The first output line is MD5: <DIGEST>, where <DIGEST> is the uppercase MD5 digest of input.self_md5.py; then the original program continues.

Write to a specific path:

py-self-md5 input.py -o output.py

Rewrite the input file in place:

py-self-md5 input.py --in-place

Replace an existing py-self-md5 prefix in place:

py-self-md5 input.py --in-place --force

Overwrite an existing output file:

py-self-md5 input.py -o output.py --force

Generate and verify in one step:

py-self-md5 input.py --check

What the wrapper preserves

  • The tool preserves shebang lines, encoding cookies, module docstrings, and from __future__ import ... placement.
  • By default, the input file is not modified.
  • Existing py-self-md5 prefixes are detected. Use --force to replace one.

Limitations

  • This is an executable self-hash wrapper, not a general MD5 collision generator.
  • The generated prefix can be large because it embeds enough bytes to reconstruct the generated script in memory.
  • --check executes the generated script, so only use it with programs you are willing to run.

Metadata

Release files for py-self-md5 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-self-md5 0.1.0
File Size Uploaded
py_self_md5-0.1.0.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-self-md5 0.1.0
File Interpreter ABI Platform
py_self_md5-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / py_self_md5-0.1.0.tar.gz

Download URL py_self_md5-0.1.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c8713e81a6f24c01404525d49386aae1ddc0dfea48834c751a1e38c45f3d2d46
BLAKE2b-256 checksum
How to use checksums
10e831d4124663bf56a9c957e3967bc59170474763bffb2aa2e7606c1c28f10d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.11.15 Windows/10

Release files / py_self_md5-0.1.0-py3-none-any.whl

Download URL py_self_md5-0.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bfce1853d380c730db3cde3f9cc342cfb4e70b39bdb7eddc7a6fcfadb5a3720
BLAKE2b-256 checksum
How to use checksums
3f00cc58847501196d09753b7fec1028204e6d1c5cb3d334a0999f2065227255
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.11.15 Windows/10

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page