What is Hashing?

Hashing

Hashing is one of the fundamental reasons that make blockchain technology as secure and great as it is now.

In short, Hashing is the process of taking a key and through a mathematical algorithm, making it into a different value. The “different value” is the hash (also known as hash value).

 A good hash is one that could not be converted to the original key.

What makes Hashing so great?

A hash is the unique product of a key.

What does it mean?

Let me show you with an example:

In this example, we are going to use SHA-256 to hash a key.

What is SHA-256?

It’s short for Secure Hashing Algorithm and is the hash function and mining algorithm of Bitcoin protocol.

But enough about that, let’s dive in.

For this example, I’m using an SHA-256 hash calculator to calculate the hash value of a key.

The key is “john”. It’s all in non-capital characters.

As you can see, the hash value of “john” is:

60976712c7f60fa538bcacf402529b41589f589de3058713b4759062cc0110ea

Now, let’s do it again, with a little change in the key. We’ll write john with a capital O.

That will be “jOhn”:

See?

The hash value is completely different:

0349f1ff9114b404a0c48550fb2855aeb53d86ed6813cd6e4a35aa45850d98a5

That’s the magic of hashing, what makes a hash value unique.

Writing a single letter in capital results in a completely different hash value.

How is hashing useful?

Let’s go over a real-life example to fully understand how hashing can be useful to us.

Imagine you have a very important document that you want to make sure it doesn’t get changed by anyone. Let’s say it’s a court order.

All you have to do is to get its hash value and keep it somewhere safe. Whenever you want to check if it has been changed or manipulated you just get its hash value again and check if it matches with the old one or not.

Useful right?

How is hashing done?

Now that we learned the basics of hashing and how hashing can be used in our day-to-day life, let’s go deeper into the subject.

There is 3 main parts in the hashing process,

Key: it’s the data that will be processed and its hash value will be calculated.

Hash Value: it’s the values returned by the hash function.

Hash Function

Now let’s find out more about Hash Functions.

What is Hash Function?

According to Wikipedia; “a hash function is any function that can be used to map data of arbitrary size to a fixed size.”

Wait.. what??

Well, to put it simply, it’s a one-of-a-kind identifier for any kind of content, we have learned about this in What makes hashing so great? part (a hint: when you change anything about the key, the hash value also changes, there is a different hash value for every piece of content).

The hash function also takes the data of any size and converts it to a ciphertext with a specific length.

Let’s go over an example to fully understand what “takes the data of any size and converts it to a ciphertext with specific length” means.

As you can see, both “Bitcoin” and “Bitcoin is the king of crypto” both generated a hash value with the same length. It doesn’t matter how many characters your key has, your hash value will always have a certain length.

Which hash is better?

To determine what makes a hash better than others, we have to check for some properties.

I. Pre-Image resistance: As I mentioned earlier, a great hash algorithm is one that would be “impossible” to recover the key from the hash value.

Now, it’s not impossible. Let’s say I hash every letter in the alphabet and give you a random hash value. Your job is to determine the letter from which the hash value has been calculated.

It is simple to do so, you just get the hash value of a random letter and compare it to the hash value I gave you.

If it matches: you are very lucky and your main job should be gambling (I’m joking obviously). Your chances of getting the right answer on the first try is roughly 4%, but it could still happen.

If it doesn’t match: you just pick another random letter and try that.

But in the end, you will be able to recover the key of the hash value.

But this method could only work if you have a certain number of keys to try, even so, there should also be a few of them, ideally, something less than 100, if there were a million of letters in the alphabet for example, the difficulty of your task would skyrocket.

So it is not impossible to recover the original key from a hash value, but it takes so much time and effort that the fact that it’s impossible or not doesn’t even matter.

II. Collision resistance: a collision happens when 2 different keys produce the same hash value.

This means the hash algorithm you are using is an unsafe one and could not be trusted with important data. Because someone could pass on artificial data as a real one, simply because they have the same hash value.

So is a good hash algorithm immune to the collision?

Well, not technically. No hash algorithm is collision-free for that matter. But it would be very hard to find one.

III. Deterministic: this means a unique key always produces the same hash value. Take “john” for example, it’s hash value should always be:

60976712c7f60fa538bcacf402529b41589f589de3058713b4759062cc0110ea

Otherwise, the hash algorithm is not a safe and reliable one.

IV. A change in key changes the whole hash value: a good hash algorithm should also change completely in hash value if you change the key even a little bit.

Doesn’t matter how small the key changes, it should always result in a very big change in the hash value.

Again, in the john example, the slightest change such as writing a capital O, changes the hash value completely and it becomes:

0349f1ff9114b404a0c48550fb2855aeb53d86ed6813cd6e4a35aa45850d98a5

This is one of the properties of a good hashing algorithm.

Conclusion

In this article, we went over some of the basics about hashing and now have an understanding of what is and how it works. To better understand blockchain technology, you should first understand hashing, as you can not fully understand concepts such as mining without knowing what hashing is.

Leave a Reply

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Get last Update & news faster on Nominex    OK No thanks