Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hashing Algorithm, its uses?

Tags:

algorithm

hash

I don't fully understand hashing algorithms. Anybody care to explain it to me in a very simply understandable way.

Thanks

EDIT: Using it with Usernames from a text file.

like image 357
ritch Avatar asked Apr 28 '10 00:04

ritch


3 Answers

There are a lot of hashing algorithms, but the basic idea is to quickly and (nearly) uniquely come up with an identifier for a piece of data. This can then be used as an index into a table so that data can be quickly looked up. Most hash algorithms have collisions, where two pieces of data will hash to the same value, but this is extremely rare for the best algorithms.

For an example of why this might be useful, let's say I hashed the entire phone book for my city. Now instead of doing a binary search when I want to look up someone's number all I have to do is run their name through the hashing algorithm then go directly to that index in my table.

like image 143
Bill the Lizard Avatar answered Nov 19 '22 01:11

Bill the Lizard


Assuming you're asking someone to basically explain a use for hashing think of an array. Now imagine a huge array where you want to find a specific piece of data that is only in one array slot. Instead of iterating through the array, you can take input data, and use that to calculate the index. Using the same formula that you used to store the data in the array, you can just jump to the location of the data you want instead of looping.

like image 33
Justen Avatar answered Nov 19 '22 01:11

Justen


Hashing algorithms try to make comparing of large data easier. Instead of comparing data to equality it is enough to compare the hash values.

There are a lot of different hashing algorithms, some of there are cryptographic hashing algorithms like MD5, SHA1, SHA256 etc. It you have two equal hash values you can be sure, that the data also the same.

like image 2
Oleg Avatar answered Nov 19 '22 02:11

Oleg