Is md5 hashing algorithm an injective function? meaning that it will generate a unique output for any given input?
If not, is there some other similar hashing algorithm that is injective?
Is md5 hashing algorithm an injective function? meaning that it will generate a unique output for any given input?
If not, is there some other similar hashing algorithm that is injective?
No, MD5 has collision vunerabilities. Other hash functions such as SHA-1 also have hash collisions, although it is much less likely than MD5.
An injective hashing function is also known as a perfect hash function. Perfect hash functions do exist, but there are certain requirements or information you will need to know about the input data before you can know that your hash is perfect.
You could look at CMPH for information on creating a perfect hash function.
md5 is not an injective function, because output is smaller than input, so you have more input possibilities than output.
I think sha-1 is not injective.
Every hash function is NOT injective. Hashes map a large domain to a significantly smaller codomain. By the pigeon-hole principle, such a function can't be injective, because there would be items in the domain that'll map to the same item in the codomain.
For example, giving a hash function a large file as input, and receiving a short checksum. There are many more possible large files (pigeons) than there are possible short checksums (pigeon-holes), so "collisions" are surely going to occur.
Here is another post that may be able to answer your question.
Technically no, but kinda yes, because there is a very slim chance for them to be the same.
Here is another post discussing this issue.
Practically, yes.
Realistically, it has been shown that it does have the potential for collisions. I would use SHA-1 instead. 1