# Where do hash functions get their preimage resistance? [migrated]

I read through this answer and it seemed to make sense to me, but when I try to make a simpler answer to explain it to myself I lose something in the process.

Here is the much simpler hash function I wrote after reading the description of how MD5 works.

1. Take in a single digit integer input as `M`
2. Define `A` to be some public constant
3. `for int i=1; i<=4; i++:`
`A[i] = (A[i-1] + M) mod 10`
4. return `A`

This hash function uses the message word in multiple rounds, which is what the answer says leads to preimage resistance. But with some algebra using mod addition we can reduce this "hash function" to just `A[i] = (A + i*M) mod 10`.

``A = (A + M) mod 10 A = (A + M) mod 10    //Substitute A in      = ((A + M) mod 10 + M) mod 10   // Distribute outer mod 10 in      = ((A + M) mod 10 mod 10 + M mod 10) mod 10 // simplify mod 10 mod 10 to mod 10      = ((A + M) mod 10 + M mod 10) mod 10    // Distribute inner mod 10      = ((A mod 10 + M mod 10) mod 10 + M mod 10) mod 10  //factor mod 10 out      = ((A mod 10 + M mod 10) + M) mod 10    // remove redudent paraens      = (A mod 10 + M mod 10 + M) mod 10  // factor mod 10 in      = (A mod 10 mod 10 + M mod 10 mod 10 + M mod 10) mod 10 // simplify mod 10 mod 10 to mod 10      = (A mod 10 + M mod 10 + M mod 10) mod 10   // factor mods 10 out      = (A + M + M) mod 10      = (A + 2M) mod 1 // Repeat with A to find A = (A + 3M) mod 10 and so on ``

Because `A[i] = (A + i*M) mod 10` is not preimage resistant, I’m confused as to what action in a hash function gives it its preimage resistance. To phrase my question another way, if I wanted to write a super simple hash function, what would I need to include to be preimage resistant?

Posted on Categories proxies