-: In this demonstration you're going to see how MD5 hashes
are created for two slightly different inputs,
creating a very large difference in their outputs.
Lets get started.
On my screen on the left,
I have an online MD5 hash generator
and on the right,
I have a text file of the US Constitution.
Now, what I'm going to do is
I'm going to copy this entire file
of the textfile of the US Constitution
and place it into the box.
And immediately what is going to end up happening,
if I go up here to the top,
I have the entire text here
and we have this hash string down here at the bottom.
Now, the hash string at the bottom is unique
to that Constitution and the word
and the order that those are in.
If I change even one letter in the Constitution,
that hash is going to be drastically changed
and I'm going to demonstrate that to you right now.
So if I go here, there's the word defence with a ce
which is the British spelling,
but as Americans, we don't spell it that way anymore.
We spell it as d-e-f-e-n-s-e.
So if I change the c to an s,
watch that has value as it changes.
I'm going to do that in 3, 2, 1, change.
Notice a vast difference in that hash.
That's why one letter makes all
the difference when you're dealing with hashes.
Because of the way that these are computed,
they come in one way and they come out a different way
and they come out the same way every time
based on what's input.
So let me show you another example of this.
Let's go ahead and say I have the line 1234567890
and I'm going to treat each line as a separate hash now.
If I went and said let's do it as 0123456789,
they're vastly different because I shifted the position.
You probably expect that.
But, what if I did 1234567890,
they're both the same now,
and I added a dot.
Well, that's going to change the bottom one, drastically.
If I go back, it's the same.
If I add a space, it changes it again.
Every time you add any differences,
whether it's one bit or one character,
it's going to drastically change that MD5 output.
And that's why MD5s are considered
a way to verify integrity.
It verifies that the original input
was never changed in transit
because the hashes match, there could be no changes.
Now, are there any cases where two different things
will give you the same hash?
Yes, this is called a collision.
They do occur because an MD5 only uses 128 bits
to represent that hash value.
That is going to give us a limited number of choices.
But there are unlimited number of inputs.
So when you have two that give you the same hash value,
that is called a collision
and that is a bad thing.
So, because MD5 only has 128 bits,
it does have more collisions than
something like SHA1 or SHA256 or SHA512.
Because as you extend that space
of what that unique hash value can be,
you have less collisions
and that's why most people have moved to SHA1,
SHA256 or SHA512 as we've move forward into the future.