MD5 etc. as a hash function

后端 未结 4 2045
逝去的感伤
逝去的感伤 2021-01-19 23:30

Let\'s say you are planning to design a hash function which will generate keys between 0-256. Will using first 2 digits of MD5-digest be a great idea for a uniform distribut

4条回答
  •  不要未来只要你来
    2021-01-20 00:21

    You haven't explained how you're going to use the hash, and what you're going to do with the collisions that are inevitable given that you have only 256 output values.

    I think even MD5 (which is not cryptographically secure any more) is overkill for the likely applications.

    I'd probably go with a CRC (cyclic redundancy check) algorithm that would generate a 16-bit or 32-bit number for you, and would likely give you good enough distribution.

提交回复
热议问题