# SHA256 - alternative algorithm to receive same hash?

My question is whether it is possible to use "another" algorithm than the sha256 to hash data but end up with the identical sha256 hash (obviously without using the sha256 algorithm)?

• Are we talking about all $m$ or just a single $m$? Are we talking a specific $m$ or looking for a collision between the outputs see here Sep 3, 2022 at 20:40
• I Like both your ideas, Forest and elderlPednt. @Forest: i get your Point. How would you evaluate If the result should be Always the First 32 Characters? Would that Be possible without going theough sha256? (and removing the Last 32 chars) @ elderlypedant: great thought. I would say No, both are Not the Same. One is obv more efficient in getting the Same result. Can this Idea Be appliwd to sha256? (make algorithm quickeer?) Sorry for typos, bumpy road Sep 4, 2022 at 9:47

Due to the pigeonhole principle, any random function will eventually produce collisions with any other random function. After all, there are far more possible inputs than there are possible outputs (for most traditional cryptographic hashes). However, there isn't any way to create an algorithm that always produces the same hash as SHA-256 for the same input without that algorithm being SHA-256.

Given two random functions $$f$$ and $$g$$ (any good cryptographic hash will adequately approximate a random function for all intents and purposes), $$\exists{m}:f(m) = g(m)$$. This means that there will exist some message $$m$$ that produces the same hash with both functions. It is also true that there can exist two different messages which, when hashed with different functions, produce the same result (i.e. $$\exists m,n: f(m) = g(n)$$, which is called a claw). However, if $$\forall{m}:f(m) = g(m)$$ (i.e. every message results in the same hash when hashed with the other function), then the functions are identical. There is no situation where that can be true but $$f$$ and $$g$$ are not the same.

• i get your Point. How would you evaluate If the result should be Always the First 32 Characters? Would that Be possible without going theough sha256? (and removing the Last 32 chars) Sep 4, 2022 at 13:40
• @user103667 Not really. I mean, you could argue that a function defined as a truncated version of SHA-256 technically isn't identical to SHA-256...
– forest
Sep 5, 2022 at 11:04
• Beware that there is no way of validating that $f = g$ by trying all $m$ as that's infeasible. It is definitely possible to generate a $g$ which is virtually identical to the hash function, but returns a different value for a certain $m$. This is obvious, just set $m$ to a random value of 256 bit, then return a specific value for that $m$, otherwise return $f$. Or, for an actual example, take hardened SHA-1. Sep 6, 2022 at 7:44

In my opinion, it depends on what you mean by “another” (ie. “different”) algorithm.

Here are two algorithms. Each one takes a number as input, and produces a new number as output:

(1)

• Take input number

(2)

• Take input number