I cant find how to decode string encoded in sha1. I'm suprised that i can't find simple function in python docs or google doing sha1 decoding. I give up. I need help..
-
You didn't try very hard. If your first search attempt doesn't work, try other variations. For example, see what comes up first when you google "python sha1". Then look at the "deprecated" warning and read the docs for the recommended module instead. I normally wouldn't post a comment saying "just google it", but since you went part way and gave up, I'm just giving you encouragement to try again. You can find it. – Todd Oct 03 '11 at 20:06
-
4And now that I gave it another moment of thought, I realize you can't decode it. These types of things are one-way hashes. – Todd Oct 03 '11 at 20:11
1 Answers
SHA1 is a hashing algorithm. Hashing is one-way, which means that you can't recover the input from the output for any non-trivial hash function. A simple example of a one-way hash function would be adding together all the digits of a number. 1234 would hash to 1 + 2 + 3 + 4 = 10, but so would 4321, 1900, 5050, and many other numbers. Given just the hash value of 10, you can't tell whether the input was 1234 or 5050 because information was lost.
Here's a graphical example:
As you can see, both John Smith and Sandra Dee are mapped to 02. This means that you can't recover which name was hashed given only 02.
Hashing is useful because it maps any amount of data to a fixed-size output and, unlike in the above examples, it is extremely difficult to find two inputs that hash to the same output. It took over 6,500 CPU-years to find just a single pair inputs to SHA-1 that have the same hash.
Therefore, if hash(A) == hash(B), then you can be confident that A == B. If you copy a huge file and the hashes of both the original and the copy are the same, then you can be pretty sure that the file is intact.
- 289,723
- 53
- 439
- 496
