Pregunta

I stumbled over this blogpost by Brian Suda and quickly applied the "Dopplr’s coloring algorithm" to some examples, and that this works is not in question. What is, is why?

The process is as follows:

$hex_color = sub-string(md5($original_string), 0, 6)

Input some string (e.g. city names as with dopplr's original usage), make a md5-hash of this, and use the first 6 digits from the hash. Prepend this with a "#" and a string is transformed into a color fit for use in CSS-documents etc.

How is it that the six first digits of a md5-hash always matches a color in the hexadecimal representation?

¿Fue útil?

Solución

MD5 always outputs hex. Colors can be represented as a 6-character hex string in css. So, the MD5 hash is just producing a semi-random hex string.

And any hex string (that is 6 characters long and begins with a #) is valid to define a color.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top