Cryptography Challenge: Crack an MD5 Hash with Ruby
Yesterday, Eric, one of the Experience Engineers here at Launch Academy came up with a little challenge for everyone in the cohort: Given an MD5 hash and a set of hints as to what the decrypted message is constrained by, write a brute-force program that will crack the hash and return said decrypted message.
MD5 hash: b354e9b8c7a5fb1e073670a28f957032
- All lowercase letters
- No spaces
- No underscores
- No numbers
- No characters other than letters a-z
- 6 characters long
(the original, by Eric, can be found here.)
I personally love these types of challenges – fun little puzzles that require understanding of not only programming, but some cryptography as well. There was even a tasty prize for the first person to not only solve it, but also actually have Ruby code to back it up (so no cheating with online decrypters!).
I managed (with some help from Prem of Thoughtbot) to write a six-line program that, after a good 10 minutes or so, does the job. There’s many different ways to implement the decrypter, as others in my cohort have shown, with differing efficiencies. For starters you’ll want to use Ruby’s Digest::MD5.hexdigest
method. Give it a try, it’s actually really fun. If you manage to solve it, see if you can get the code down to as few lines as possible (hint: there are Ruby methods for permutations), or, even harder, how to reduce the time it takes to decrypt. I’ll post a Gist of the solution sometime later.
I, unfortunately, did not figure it out before fellow Launcher Ben Calegari did. Kudos to him and him receiving his just reward: a delicious cannoli.