dongmiao260399 2017-09-06 09:34
浏览 77

md5的一部分有多独特?

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

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

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

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);
  • 写回答

3条回答 默认 最新

  • dongmei8071 2017-09-06 09:43
    关注

    As you are asking about uniqueness of your string, it's actually a probability. Means as much string character you will use and as much the length of random string you make will get less chances of getting similar random string.

    So, to get unique string you need to store string in your DB and compare with random string, if you found similar then again go for new fresh string , until you get unique string.

    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示