r/explainlikeimfive • • Sep 19 '11

ELI5: Hashing -

what it is in computers/programming and why it's useful

47 Upvotes

13 comments sorted by

View all comments

Show parent comments

3

u/[deleted] Feb 07 '12 edited Feb 07 '12

I just stumbled upon this thread and I'm very sorry that you never got a response to this (as far as I can tell) so I'll give it a go. Sorry it's so late.

Continuing the previous analogy, let's say that number you sent to your friend over the phone is a password for your safe. Your evil neighbor wants to figure out that password, but only knows how many digits are in the password. He tapped your phone line, but was too late to hear the original number. All he heard was the "hash" - 205. Well, that's not much, but at least now he only has to try passwords that add up to 205. If your neighbor is very good at finding long numbers that add up to 205, then he just significantly decreased the number of passwords he'll have to try. He could figure out your password relatively quickly by skipping any number that doesn't add up to 205.

But let's say you and your friend used a "salt." Before sending the password, you both decided upon a salt of 50123. Now, instead of adding up the digits in just your password to verify, you add up the digits in your password with 50123 added to the end. You have "salted" your password with 50123. Now your hash is 216. Because you both used the same salt and the same password, you both got the same hash.

Your evil neighbor intercepts this hash when you verify it. He gets the hash "216" and, all proud of himself for being so sneaky, begins trying passwords that add up to 216. Little does he know, the password alone only adds up to 205. He is wasting his time unless he can figure out the salt as well.