Quick MD5 question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aclees86
Forum Newbie
Posts: 5
Joined: Sat Jun 06, 2009 11:58 am

Quick MD5 question

Post by aclees86 »

I've heard that sometimes generating a MD5 string in PHP can return a different string to an MD5 generated in C++. From what I can find on the internet there seems to be some truth in this somewhere but I can't find out why this is or how to prevent it happening... Does anybody have a solution?

Also, having never really taken the time to look at MD5 strings properly before I have noticed that out of 100,000 MD5 strings I have just been given (don't ask!) the characters of each string contain only 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f. Does anybody know why this might be? I've had a look around the 'net and could not really see much to explain this... Anybody?

Many thanks
Antony
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Quick MD5 question

Post by Eric! »

md5 in php returns a 128bit in 16 octets as a hexadecimal number 32 digits long, it isn't a string of ascii characters. http://en.wikipedia.org/wiki/Hexadecimal

They will be the same between php and C if they are implimented correctly and shown in the same format. Here is the method and c code http://tools.ietf.org/html/rfc1321
aclees86
Forum Newbie
Posts: 5
Joined: Sat Jun 06, 2009 11:58 am

Re: Quick MD5 question

Post by aclees86 »

Thank you.

I feel rather stupid now, as I did not pick up on the fact that the algorithm returns a result as a hexidecimal number. I briefly looked at the way in which it is calculated but missed this entirely. I also didn't put 2+2 together to work out the characters given were all hexidecimal.

Thank you for providing me with a little more information regarding the C implementation.

Regards
Antony
Post Reply