开发者

Can an MD5 hash have ONLY numbers or ONLY letters in it?

开发者 https://www.devze.com 2023-03-22 17:40 出处:网络
I have been researching but I am clueless开发者_JAVA百科. I know that MD5 can have both numbers and letters but if I ever find a case where an MD5 has only numbers or only letters it breaks my script

I have been researching but I am clueless开发者_JAVA百科. I know that MD5 can have both numbers and letters but if I ever find a case where an MD5 has only numbers or only letters it breaks my script currently


List of few first strings that give only-digit md5 hash:

ximaz : 61529519452809720693702583126814 
aalbke : 55203129974456751211900188750366 
afnnsd : 49716523209578759475317816476053 
aooalg : 68619150135523129199070648991237 
bzbkme : 69805916917525281143075153085385 

Here's one with only letters:

cbaabcdljdac : cadbfdfecdcdcdacdbbbfadbcccefabd


You have 32 digits. If we assume all ciphers equally distributed, there are 10^32 combinations, just made of numeric ciphers, 6^32 combinations of just alphabetic ciphers, and 16^32 combinations in total.

Which makes a (10^32 + 6^32) / 16^32 probability that your script will fail, on each invocation.

 echo "scale=10;(10^32 + 6^32) / 16^32" |  bc 
.0000002938

So once in about 3.4 million cases it will fail. How often do you want to use it?


Theoretically, yes, an MD5 hash (when converted to a hexadecimal string) could contain only decimal digits or only letters.

In practice, also yes: the string ximaz yields an MD5 hash of 61529519452809720693702583126814. Try it!

(Thanks to PHP Sadness for the example)


MD5 was intended to be a good hash function (currently broken, should not be used security applications) which means that it produces random looking output so that all possible values that fit into output space are utilized. Those letters and numbers are hex representation of the output. Yes, sometimes you could get output that consists of letters only or numbers only, but most of the time you will have both.

If I had to parse hex representations of MD5 I would surely take time to support those rather rare cases when output is letters only or numbers only.


I know this is a very old question, but I found three more strings with only numbers in their md5 hashes, and Google couldn't find anything while searching these hashes so I thought it might be worth posting these:

Ioktak : 54948232518148653519995784773259
'99x\`b0x\'b : 24034969117462298298932307218853
uttuJ## : 74616072929762262275291990931711


I believe you are working with the hex representation of the MD5 hashes. MD5 hashes are actually 128-bit strings. Most tools print them with the hex-representation which amounts to 32 hexadecimal digits. Hexadecimal digits use 0-9 and a-f.

Example:

susam@swift:~$ echo -n "foo" | md5sum
acbd18db4cc2f85cedef654fccc4a4d8  -
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号