Just a quick point, but it's important. As the hash can't be 100% guaranteed to be unique (it's just highly likely to be unique) it can only be used to determine if something is different, not to see if two things are the same (although the typical mis-use is to compare for similarities). Given the hash space of Sha1, it's fairly unlikely there will be a hash collision, but not impossible (just look to the recent issues on WebKits SVN repository caused by hash collisions). Like I said, it's a small point, but an important one nonetheless.
Hashes are also used for passwords, which are the epitome of "hey, make sure that the hash is unique to only one password!"
It's important to know that there are special hash algorithms for passwords that are specifically made for shorter strings (rather than files), and take a relatively long time to compute (so that it's harder to brute-force them).
I would not recommend shadowing the built in hash function, as it may cause problems. I'd name the import crypt_hash, just to distinguish between the two. Other than that this is a good article! Simple and to the point as I like it :)
Hashing is a method of determining the equivalence of two chunks of data.
A cryptographic hash function generates a unique string for any set of data.
First two lines more mislead than explain, and as Ashley Sheridan pointed out they are not completely correct.
Why not just use shasum utility? I think it's available in all linux distros:
ayanami@frater260 ~ 18:23:25$ shasum /bin/bash
ayanami@frater260 ~ 18:24:57$ shasum -a 256 /bin/bash
ayanami@frater260 ~ 18:24:02$ shasum /bin/*
(by using -a we can specify which version of the sha we want computed - this way it's more portable than using sha256sum, sha512sum, etc)
Thought it was an article about Data Structures . Nice One . But try to write something more .
Sweet and Simple.
what abount salting?
This is a great, simple article!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.