npm install js-sha3
):John Smith
is hashed to the hash value 02
and Lisa Smith
is hashed to 01
. The input texts John Smith
and Sandra Dee
both are hashed to 02
and this is called "collision".hello
and ehllo
will have the same hash code. Better hash functions may use the Merkle–Damgård construction scheme, which takes the first byte as state, then transforms the state (e.g. multiplies it by a prime number like 31), then adds the next byte to the state, then again transforms the state and adds the next byte, etc. This significantly reduces the rate of collisions and produces better distribution.SHA-256
and calculate the hash value of certain text message hello
:hello
) from its hash value (in the above example 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
). It is well-known that cryptographic hash functions cannot be reversed back, so they are used widely to encode an input without revealing it (e.g. encode a private key to a blockchain address without revealing the key).SHA3-512
and calculate the hash value of the same text message hello
: