MD5 Flag Generator

This trick was inspired by Brian Suda who I saw speak at Whisky Web.

  1. Take a string, any string.
  2. Hash it using MD5.
  3. Substring the hash to get a 6-digit hex code.
  4. Take a look at what colour that hex code represents.

A really simple, really cool way of generating seemingly random colours, that can be used to represent things.

I had a play with this idea and used it to generate a simple flag for any input string:

<?php

$thing = $_GET['thing'];

$md5 = md5($thing);

$col1 = substr($md5, 0, 6);
$col2 = substr($md5, 6, 6);
$col3 = substr($md5, 12, 6);

echo
    "<div style='float:left;width:100px;height:200px;background:#{$col1}'></div>\n" .
    "<div style='float:left;width:100px;height:200px;background:#{$col2}'></div>\n" 
    "<div style='float:left;width:100px;height:200px;background:#{$col3}'></div>";

This takes an input string via the GET method variable ‘thing’ and turns it in to a 3-stripe flag. Examples:

” (empty string):

‘ben’:

‘bennuttall’:

‘bennuttall.com’:

See this on github: github.com/bennuttall/MD5-Flag-Generator/

Check out Brian’s book Designing With Data

Also have a play with this – I put the code up on my site here

Published by

Ben Nuttall

Raspberry Pi Community Manager. Into free software, maths, kayaking, GitHub, Adventure Time & Futurama. @ben_nutall on Twitter