有没有情况下散列算法可以保证唯一? [英] Are there circumstances where a hash algorithm can be guaranteed unique?

查看:159
本文介绍了有没有情况下散列算法可以保证唯一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用散列算法散列大小受限的相似数据(例如社会安全号码),该散列算法的字节大小比数据大(例如,sha-256),那么散列值将保证相同作为原始数据的唯一性?

解决方案

散列冲突的概率与输入字符串的大小无关只要它表明需要多少输入来保持唯一性)。尽管可能性为1 /(2 ^位长),当使用完美散列算法对0和1进行散列时,可能会发生散列冲突。在SHA-256的情况下实际上是零。

哈希碰撞是生日悖论问题。在256位散列的情况下,两个输入之间发生冲突的概率完全取决于输入的计数,并且是:


  • 1 - (2 ^ 256)! /((2 ^ 256 ^ inputcount)*(2 ^ 256-inputcount)!)或其他人所说的 - 对于合理数量的输入,基本为零


If I'm hashing size-constrained similar data (social security numbers, for example) using a hash algorithm with a larger byte size than the data (sha-256, for example), will the hash guarantee the same level of uniqueness as the original data?

解决方案

The probability of a hash collision has nothing to do with the size of the input string (except to the extent that it indicates how many inputs you need to keep uniqueness among). It's possible to have a hash collision when you hash 0 and 1 using a perfect hash algorithm, although the possibility is 1/(2^bit-length). Which in the case of SHA-256 is effectively zero.

Hash collisions are a birthday paradox problem. In the case of a 256 bit hash, the probability of a collision among two inputs is purely dependent on the count of inputs and is:

  • 1 - (2^256)! / ((2^256^inputcount) * (2^256-inputcount)!) or as others have said -- basically zero for reasonable numbers of inputs.

这篇关于有没有情况下散列算法可以保证唯一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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