2

This is getting me crazy, my md5's don't agree. I have this string:

The Combinations Generator is a tool that allows you to easily create a series of combinations by selecting the related attributes. For example, if you're selling t-shirts in three different sizes and two different colors, the generator will create six combinations for you.

When I hash it on my computer using the md5 function (with php 5.5.0) it produces the following hash: 422f3f656e1a5f95e8b5cf7565d815b5

http://www.miraclesalad.com/webtools/md5.php agrees with my computer's result.

http://www.md5.cz/ disagrees with both my computer and miraclesalad.

This string/md5 pair was initially computed by another computer which also gives the same result as md5.cz.

I read about encoding issues (although the string doesn't contain any non ASCII characters), so I tried the following code on my computer:

<?php

$str = "The Combinations Generator is a tool that allows you to easily create a series of combinations by selecting the related attributes. For example, if you're selling t-shirts in three different sizes and two different colors, the generator will create six combinations for you.";

echo "$str<BR/>";
echo md5($str)."<BR/>";
echo md5(utf8_encode($str))."<BR/>";
echo md5(utf8_decode($str))."<BR/>";


die();

The output is:

The Combinations Generator is a tool that allows you to easily create a series of combinations by selecting the related attributes. For example, if you're selling t-shirts in three different sizes and two different colors, the generator will create six combinations for you.

422f3f656e1a5f95e8b5cf7565d815b5

422f3f656e1a5f95e8b5cf7565d815b5

422f3f656e1a5f95e8b5cf7565d815b5

So it is not about utf8.

Any idea what's happening?

1
  • There is a difference between the inputs of those two pages. One is single line and the other is a text block. A single char a hashes the same. The difference is likely due to some whitespace difference such as line breaks. The input you provided in your OP is formatted for SO so we can't tell exactly what you're doing...
    – Paul Sasik
    Aug 23, 2013 at 21:18

4 Answers 4

5

My best guess is that it has something to do with the ' mark in the word "you're" and character encodings. If you remove that quote both sites report the same md5.

3
  • What? That's right. That's somewhat astounding. Maybe one of those sites is escaping wrong. Aug 23, 2013 at 21:12
  • any idea how to fix it? On my machine I mean, I don't care if the two websites disagree. I need to obtain the same result as md5.cz
    – djfm
    Aug 23, 2013 at 21:13
  • yep, they probably do something silly like md5(addslashes($str)); or even worse they could be running with magic_quotes turned on :)
    – Tjofras
    Aug 23, 2013 at 21:19
0

I tried feeding the string above incrementally to both sites you linked to in your question, and it turns out that the character breaking the generator at md5.cz is the apostrophe in if you're selling t-shirts.

If you strip the string of special characters before feeding it to a hasher, possibly preserving the string's uniqueness using something like urlencode(), you should get matching hashes for any string.

0

The strings need to be exactly the same, including the whitespaces. Probably the sites are using some transformation like trim() or stripslashes(). md5 will return the same value only if the strings are exact.

-1

md5 is md5. That's all there is to it. If you get different hashes from different (non-buggy) implementations, then you're feeding in diffent inputs. Remember that md5 is DESIGNED to produce wildly different outputs if the input(s) are even slightly different. A single whitespace character (tab, linebreak, etc...) at the end of one of your test strings will totally trash your expected hash, because you've fed in a different input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.