Hey, friends on WeChat, have you ever wondered how various files and passwords stored on our computers are kept from being 'lost' or 'impersonated'?
Today, let’s reveal a behind-the-scenes little hero—the hash function! Doesn’t it sound like some kind of secret manual from a martial arts novel? Don’t worry, it’s actually much simpler and more interesting than you think!
What is a hash function? It's like a 'juicer'!
Imagine you have a magical 'juicer' (hash function).
You can put anything in (input):
It can be a piece of text, an image, a video, or even your bank card password.
It will output a fixed-length 'fingerprint' (output):
No matter how large or complex the input is, the length of this 'fingerprint' is always fixed and looks like a string of gibberish.
This 'fingerprint' is technically called a hash value or hash code.
What’s special about this 'fingerprint'?
This 'fingerprint' (hash value) is not generated randomly; it has several very important characteristics:
Unique (as much as possible): Theoretically, if you input different things, the 'fingerprint' you 'juice' out should be different. Of course, there are so many different things in the world that occasionally two different inputs may 'juice' out the same 'fingerprint', but that’s as rare as winning the lottery.
One-way and irreversible: You can easily put something into the 'juicer' to get a 'fingerprint', but with this 'fingerprint', it is impossible to know what you had put in before! It's like drinking juice; you can't turn it back into the original fruit.
A slight change in input leads to a vastly different fingerprint: Even if you only make a small change to what you put in (like changing one character in a sentence), the 'fingerprint' produced will change dramatically and be completely different!
What is this thing good for?
You might ask, what's the use of creating such a 'fingerprint'? Don't worry, it's quite useful!
Verify if a file has been tampered with: For example, if you download software, the website usually provides the 'fingerprint' (hash value) for that software. After downloading, you can use a hash function to calculate the 'fingerprint' of the file you downloaded. If it matches exactly what you saw on the website, it means your file wasn't secretly modified during the download process and is complete and secure.
Store passwords: Websites usually do not store your plaintext password directly (which would be troublesome if hackers stole it!). They will use a hash function to 'juice' your input password into a 'fingerprint' and store it. When you log in next time, the password you enter will be 'juiced' into a 'fingerprint' and compared with the one stored earlier. If they match, it means the password is correct. This way, even if the database is stolen, what hackers get are just a bunch of 'fingerprints', making it hard to reverse-engineer your actual password.
Blockchain technology: The blockchain technology we talked about before heavily uses hash functions to ensure data security and immutability. Each block of data is linked together like a 'fingerprint'; any modification to previous data will cause all subsequent data's 'fingerprints' to change, making it easy to detect.
To summarize: the hash function, our data's 'guardian'!
So you see, this somewhat mysterious hash function is actually like a 'fingerprint' for our data, helping us verify data integrity, securely store passwords, and even playing a significant role in many high-tech fields.
Next time you download a file or log into a website, think about the 'hash function' quietly working behind the scenes. Doesn’t it seem pretty cool?
Doesn't the hash function seem easier to understand now? If you find it interesting, share it with your friends! Next time, we can talk about more interesting tech trivia!