Bits changed
Hex digits changed
Digest size
Size of A
A
Digest
B
Digest
Flipped Bit 1 in both Bit 0 in both
Hash function Bits Digest (A) Status

The avalanche test

The birthday attack

    Digest as

    More information about hash functions

    Hash function playground

    A hash function turns any text, from one letter to a whole book, into a short fingerprint of fixed size. Change a single character and a good hash gives a completely different fingerprint; yet nobody can run it backwards or find two texts with the same one. Type two messages that differ by one character and compare their digests bit by bit, see the same text under six hash functions from SHA-256 to a toy checksum, measure the avalanche effect over a thousand changes, and find a collision yourself on a shortened digest. Type message A and pick a hash function. Message B starts as A with one character changed: compare the two digests, with every flipped bit marked in the grid. Press Change one character for another small change, or type in B yourself. The table shows A under every hash function; click a row to use it. Press Run the test to flip one input bit a thousand times and see how many digest bits change, and Find a collision to see how quickly two messages share the first bits of their digests.

    How it works

    1. Type message A and choose a hash function. Message B is A with one character changed; their digests are shown with every changed digit and every flipped bit marked.
    2. Press Change one character for another small change, or edit B yourself, and click a row of the table to switch between SHA-256, SHA-512, SHA-1, MD5, CRC-32 and the toy sum.
    3. Press Run the test to measure the avalanche effect, and Find a collision to see the birthday attack on the first 8 to 32 bits of the digest.

    What makes a good hash

    A cryptographic hash must be quick to compute and give the same digest for the same input every time. Beyond that it must be one-way: from a digest you cannot work out the input except by guessing. It must resist collisions: nobody can find two inputs with the same digest. And it must show the avalanche effect: change one bit of the input and every bit of the digest flips with a chance of one half, so a small change gives a digest that looks unrelated. With SHA-256, changing the last letter of a sentence typically flips about 128 of the 256 bits.

    Why the birthday paradox matters

    In a room of 23 people two share a birthday more often than not, although there are 365 days. Digests behave the same way. With k bits there are 2ᵏ possible values, but two random messages share a digest after only about √(2ᵏ) tries, the square root. A 32-bit digest falls after some 80,000 messages, a fraction of a second here. That is why a digest needs twice as many bits as the security it should give: SHA-256 offers 128-bit protection against collisions, while MD5, with 128 bits and weaknesses in its design, is broken.

    Frequently asked questions

    Why does one character change the whole digest?

    Because a hash mixes every input bit into every output bit, many times over. SHA-256 runs 64 rounds of shifts, additions and logical operations on its state; after a few rounds a change in one input bit has spread to all of the state. The result looks random: on average half the digest bits flip, and which ones cannot be predicted. The toy sum in the app has no such mixing, which is why one changed letter changes only a bit or two of it.

    Can a hash be reversed?

    No. A digest has a fixed size, so countless inputs share every digest, and a good hash gives no clue which one was used. The only way back is to guess inputs and compare digests. That works for short or common inputs, which is why passwords are stored with a slow, salted password hash such as bcrypt or Argon2 rather than a plain SHA-256.

    Why are MD5 and SHA-1 called broken?

    Because researchers found ways to make collisions far faster than the birthday attack: two different inputs with the same digest. For MD5 this was shown in 2004 and is now possible in seconds on a laptop; for SHA-1 Google and CWI Amsterdam published two different PDF files with the same digest in 2017. Neither should be used for signatures or certificates any more. SHA-256 and SHA-512 have no known weakness of this kind.

    What is the difference between a checksum and a cryptographic hash?

    A checksum such as CRC-32 is built to catch accidental errors, such as a flipped bit in a download or on a disk, and it does that very well. But it is easy to compute backwards, so anyone can change a file and adjust it to keep the same checksum. A cryptographic hash is built to resist a deliberate attacker as well.

    Is my text sent anywhere?

    No. Every digest is computed in your browser by the app's own code, and your messages stay in this browser's local storage.

    Ready to try it?

    Open PictorX in your browser — no install, no credit card required to start.

    Go to Editor