RickyA
RickyA

Reputation: 16029

What has the least collisions for a non unique str: md5 or sha1

I want to create a unique hash for a given string and I was wondering if there is a difference in duplicate hashes for md5 and sha1.

Lets for the sake of argument assume the following code:

foo = "gdfgkldng"
bar = "fdsfdsf"
md5(foo)
>>>> "25f709d867523ff6958784d399f138d9"
md5(bar)
>>>> "25f709d867523ff6958784d399f138d9"

Is there a difference in the probability of this occurring between sha1 and md5? Also: if I use strings that have a big overlap ("blabla1", "blabla2") is there a difference?

BTW. I am not interested in the security of the algorithms I just want to create a hash that is as unique as possible.

Upvotes: 3

Views: 733

Answers (1)

Cairnarvon
Cairnarvon

Reputation: 27772

MD5 has a digest size of 128 bits. SHA-1 has a digest size of 160 bits. Even ignoring discovered weaknesses, MD5 is going to produce more collisions just because it has a smaller output space.

Consider using SHA-256 instead; it has a digest size of 256 bits (obviously), and furthermore hasn't been broken in a meaningful way.

Upvotes: 5

Related Questions