Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused about hashes

Tags:

hash

say I have a blob of text 5000 characters. I run it through a hashing program and generates a 40 char long hash. now i run another blob of text, 10000 characters. it still generates a hash 40 chars long. that's true for text of any length.

my question is if the hashes are all unique, wouldn't i be able to compress anything into a 40 char string?

like image 572
chat Avatar asked Nov 27 '22 22:11

chat


2 Answers

Hashing is not unique.

Hashing is a technique to attempt to generate a unique hash for each value fed to it, but it is not guaranteed unique.

Good hashing algorithms will have duplicate hash values much less frequently than bad hash algorithms. Also, hashing is one directional - meaning you can't go from a hash -> original, so it's not meant for compression.

And: A hash doesn't need to be unique. The same input needs to be tranformed into the same hash by the algorithm. You don't use a hash as identifier!

like image 170
Reed Copsey Avatar answered Feb 28 '23 04:02

Reed Copsey


Not all hashes are guaranteed to be unique. The wikipedia entry on the topic is pretty good: http://en.wikipedia.org/wiki/Hash_function

like image 20
pdwetz Avatar answered Feb 28 '23 05:02

pdwetz