views:

164

answers:

4

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.

+2  A: 

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.

Bill the Lizard
Thanks, this helped.
ritch
+1  A: 

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.

Justen
Thanks, this helped.
ritch
A: 

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.

Oleg
Thanks, this also helped.
ritch
A: 

A hash means a 1 to 1 relationship between data. This is a common datatype in languages, although sometimes its called called a dictionary. A hash algorithm is a way to take an input and always have the same output, other wise known as a 1 to 1 function. An ideal hash function is when this same process always yields a unique output. So you can tell someone, here is a file, and here is its md5 hash. If the file has been corrupted during then the md5 hash will be a different value.

In practice a hash function will always produce a value of the same size, for instance md5() is will alway return 128bits no matter the size of the input. This makes a 1 to 1 relationship impossible. A cryptographic hash function takes extra precautions in making it difficult to produce 2 different inputs with the same output, this is called a collision. It also makes it difficult to reverse the function. Hash functions are used for password storage because it if an attacker where to obtain the password's hash then it forces the attacker to break the hash before he can use it to login. To break hashes attacks will take a word list or an English dictionary and find all of the corresponding hash values and then iterate though the list for each password looking for a match.

md5(), sha0 and sha1() are all vulnerable to a hash collision attacks and should never be used for anything security related. Instead any member of the sha-2 family, such as sha-256 should be used.

Rook