md5的一部分有多独特? [英] how unique is a portion of md5?

查看:109
本文介绍了md5的一部分有多独特?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对md5函数的唯一性有疑问.

I'm having a question regarding the uniqueness of md5 function.

我知道md5(具有微时间值)不是唯一的,但是,它们是非常独特的:)

I know that md5 (with microtime value) are not unique, however, they are pretty unique :)

如何计算md5哈希值的两个部分之间发生冲突的可能性?

How can I calculate the probability of a collision between two portions of an md5 hashes?

例如:php中的以下代码可从md5结果生成8个字符的字符串:

For example: The following in php that generates a 8 chars string from md5 result:

substr(md5(microtime()), 0, 8);

第二种情况-如果它的索引是唯一的(那么它每次都会获得哈希的不同部分)怎么办?

A second scenario - What if the index of it is unique (so it gets a different portion of the hash each time)?

substr(md5(microtime()), rand(0, 32), 8);

推荐答案

有8个十六进制数字的2 ^ 32组合.即使它们是完全随机的,在获得2个相同的字符串之前,平均也只能生成大约65000个这样的字符串.

There are 2^32 combinations of 8 hexadecimal digits. Even if they are completely random, you can only generate about 65000 such strings, on average, before you get 2 that are the same.

md5()不会显着更改任何内容.但是,如果生成速度太快或跨很多机器生成,那么情况就更糟了,因为您很有可能最终会两次使用相同的microtime()值.

md5(), using a random index or not, doesn't significantly change anything as long as all the microtime() values use use are unique. But, if you are generating these too fast, or across many machines, then the situation is much much worse, because there's a good chance you could end up using the same microtime() value twice.

这篇关于md5的一部分有多独特?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆