A Hash Is Not a Key
A digest has no secret in it, so anyone can hash a guess and compare; find which of three guessed words has a given digest, and see why a guessable input is not hidden by hashing it.
The question
A site stores the SHA-256 digest of a word instead of the word. Someone who reads the stored digest cannot run the hash backwards in any way this page shows. Can they still find the word?
They can try. SHA-256 takes no key: anyone can compute it, and the same input always gives the same digest. So a person with a list of guesses can hash each guess and compare the result with the stored digest.
Work it by hand
Take the stored digest 0f78fcc4 86f53154 18fbf095 e71c0675 ee07d318 e5ac4d15 0050cd8e 57966496 and the guesses plum, grape and fig.
The digest of plum starts with 04, and the digest of fig starts with 8c. The digest of grape starts with 0f78fcc4, and that matches the stored digest in all 64 hex digits. The word is the second guess, index 1 when you count from 0.
A first digit that agrees is not a match. Two different words can start with the same hex digit, so you compare the whole digest. Nothing in the stored digest said which guesses to try: the guess list did all the work.
Run it
The program reads a stored digest in the box fingerprint and a list of words in the box words, one per line. Line 1 splits the list into lines. The loop that starts at line 3 hashes each word with SHA-256, and line 5 compares the whole digest with the stored one. The program returns the word that matches, and the text no match when none does.

let lines = str_split(words, "\n");
let answer = "no match";
for (i in range(0, lines.len())) {
let d = ssl.digest("SHA256", lines.at(i));
if (d == fingerprint) { answer = lines.at(i); }
}
lmcode_return_put("count", lines.len());
{
"answer": "grape",
"count": 3
}You can change both boxes: printable ASCII and newlines, up to 2048 bytes each. A digest that matches none of the words returns no match, and so does an empty digest box. Write the stored digest in lowercase: capital letters match nothing. An empty word list is one empty line, which matches only the digest of the empty message, e3b0c442 and so on; the word returned is then the empty text.
Your turn
The program below is meant to return the index of the first line of candidates whose SHA-256 digest equals the digest in target, or -1 if none does. The digest is 64 lowercase hex digits. Read how it searches and judge each result. Check runs it on the data shown and on seven others.

let lines = str_split(candidates, "\n");
let answer = -1;
for (i in range(0, lines.len())) {
let d = ssl.digest("SHA256", lines.at(i));
if (d == target) {
answer = i;
}
}
{
"answer": 3
}candidates holds words, one per line. target is a SHA-256 digest as 64 lowercase hex digits. Return, as an int, the index of the first line of candidates whose SHA-256 digest equals target, counting from 0, or -1 if no line does. Check runs your program with other candidate lists and targets.
Read the result carefully
The page finds a word among three that it was given. It does not say how many guesses a real search needs, and it does not show how a site should store anything: that is a question about slowing the guess down, which Keys From Passwords takes up.
A digest is also no tag. It protects no message from a change, because anyone can compute a new digest for a changed message; a keyed tag is the tool for that, and A tag catches the change shows it, HMAC uses two pads builds it from a hash, and A Merkle root catches a change shows what hashes of chunks give.
Recap
- A digest has no key: anyone can compute it, so anyone can test a guess.
- The same input always gives the same digest, which makes a match certain when the guess is right.
- The stored digest did not say which words to try: the list of guesses did the work.
- A fixed-speed hash of a guessable word hides little; the next step is a keyed or slowed function.