educative.io

.."now we left with only 8 charachter per key.." can someone explain what are they talking about?

They choose MD5 which means there are 128bits which are16B.
To encode 16B of binary with Base64 encoding you need 22B.
Now from there to “now we are left with only 8 characters” I have no clue what are they saying?

What am I missing?

They’re saying the short key should either be 8 or 6 characters (short key meaning the tiny_url that is being generated). You need to disregard when they say “now” in “now we are left with only 8 characters”. I think that’s your source of confusion

In order to represent a base64 character, you need 6 bits. 128bits/6bits ~= 21.33333. Which means when we use MD5 to create our hash, and after base64 encoding it, we’ll end up with a string with more than 21 characters. We’re going to take the first 6 or 8 characters of those 21+ characters.

The reason why they say 6 or 8 characters is because they were debating on what the length of the short key (tiny_url) should be at the beginning of the problem

2 Likes

Thanks for this! You’re right, the “now” was confusing me.