← Blog

A PNG that shows its own MD5 digest: The Arma Of Efe hashquine

How did we build a PNG that writes its own MD5 digest into its own pixels, without a ready-made template? Hashes, collision keys, PNG layers and a search for efe23…23efe on an RTX 5070, in an interactive walkthrough.

The image above is not an ordinary logo. Running from top to bottom along the arc on the right, it reads efe235ae1b88c53e73d1c11515623efe, and that is the file’s own MD5 digest. Download the image and run md5sum, and you will see the same 32 characters.

Files like this are called hashquines. The famous example online is retr0id’s dragon PNG, and most people use that ready-made template. We built ours from scratch, with no template, using our own logo (The Arma Of Efe), our own blog link, and a custom digest that starts and ends with efe. Below, I walk through the process step by step, including what we tried along the way.

Retr0id’s dragon PNG hashquine that shows its own MD5

The PNG hashquine by David “Retr0id” Buchanan, MD5 1337e2ef42b9bee8de06a4d223a51337. Image: Retr0id, via corkami/collisions.

What is a hash, and why does every character change?

A hash (digest) is a fixed-length fingerprint derived from a file’s contents. MD5 is a digest function designed by Ronald Rivest in 1991. Whether the input is 1 byte or 50 GB, the output is always 128 bits, or 32 characters made of 0-9 and a-f.

The key property of digest functions is the avalanche effect: the smallest change in the input changes the output from start to finish. Try typing something below:

The chicken-and-egg problem

Because of the avalanche effect, an image that carries its own MD5 looks impossible at first glance:

  1. You draw the image and take its MD5, for example 4a8c91e0….
  2. You write that code onto the image and save it.
  3. The pixels have changed, so the file’s MD5 is now something else, for example 9f02d71a….
  4. You write the new code, and the digest changes again.

To break this loop, we need to look inside MD5.

The idea that breaks the loop: keys that leave the MD5 unchanged

MD5 does not process a file in one pass. It splits the file into 64-byte blocks and processes them in order. The starting state (IV) is mixed with the first block, producing an intermediate state (IHV). That state is mixed with the next block, and so on until the file ends. The final intermediate state is the 32-character MD5 itself.

The key point is this: you can find two different 128-byte data pieces (A and B), aligned to the 64-byte boundary, that both produce the same intermediate state. This is called a same-prefix collision, and tools like FastColl produce one quickly. Since every block after that piece sees the same intermediate state:

  • If A is included, a line segment appears on screen. If B is included, it does not,
  • but the MD5 at the end of the file never changes.

So each collision pair is a key that opens and closes without breaking MD5. First we compute the file’s MD5, then we tune the keys so they draw exactly that digest. Because the digest does not change, the loop is broken.

How the arc was drawn, character by character

In our file, 32 characters are arranged from top to bottom along a curve that follows the logo’s arc. Each character is a seven-segment digit, and each segment is drawn by its own key: 224 keys in total. Use the slider to follow how the digest is placed on the arc:

Since we did not use a ready-made template, the PNG had to pass four validation layers at once:

  1. 64-byte alignment: Each key must land exactly on the offset % 64 == 0 boundary in the file. We aligned every key to this boundary by inserting empty zero-length blocks into the DEFLATE stream.
  2. PNG Sub and Up filters: We made palette indexes 0..254 black and only index 255 white. The two halves of a collision pair differ in the top bit of a few bytes. In a Sub-filtered row, that difference shifts each following pixel by 128 and turns into a horizontal line; Up-filtered rows carry it downward. We chose the bytes after each key so the line is pure 255 (white) in one state and black in the other.
  3. Zlib Adler-32 balancing: When compressed data is decompressed, it passes an Adler-32 checksum, and each key shifts that sum by a few hundred units. We placed 160 balancing keys in the black rows, and we chose the subset that restores the sum exactly using dynamic programming and a meet-in-the-middle search.
  4. IDAT CRC-32 verification: Each IDAT chunk ends with a 32-bit CRC-32. We placed 40 extra blocks right after the compressed stream and solved a linear system over GF(2) with Gaussian elimination, fixing the CRC-32 value to 0x1807EFE0.

A custom digest: each character multiplies the work by 16

Showing the file’s own MD5 was not enough. We wanted the digest to start and end with efe. To do that, we changed a 64-byte nonce block at the end of the file and tried billions of digests.

Each character can take 16 different values, so every additional fixed character multiplies the average number of attempts by 16: N fixed characters need on average 16^N attempts. In a simple C loop on our 24-core CPU, we could try 177 million MD5s per second. Running the same job through OpenCL on the RTX 5070 laptop GPU raised the speed to 3.54 billion per second, about 20 times faster. An efe23…23efe digest takes 1.1 trillion tries on average; ours came after 90 billion tries, in about 25 seconds.

Change the number of fixed characters with the slider. The results we actually found are marked with dots:

Verify it yourself

Download the image and run it in a terminal. On Windows, use certutil -hashfile file.png MD5; on macOS, use md5 file.png:

$ md5sum the-arma-of-efe-23-hashquine.png the-arma-of-efe-hashquine.png
efe235ae1b88c53e73d1c11515623efe  the-arma-of-efe-23-hashquine.png
efe8d2bee9dc7b5815f72581e5c17efe  the-arma-of-efe-hashquine.png

The 32 characters in the output match exactly the code written from top to bottom along the arc.

The code that generates the image is on GitHub: the-arma-of-owl/the-arma-of-efe-hashquine. The collision skeleton is in the repository too, so you can generate a new hashquine with your own nonce value.

Sources: Retr0id - MD5 collision with CRC32 preimage ↗ · Ange Albertini - Hashquines ↗