How much can you truncate a SHA1 hash and be reasonably sure of having an unique ID?

后端 未结 5 1408
借酒劲吻你
借酒劲吻你 2020-12-24 13:41

I am making an application that stores documents and gives each one a UID based on a SHA1 digest of a few things including the timestamp. The digest has a lot of characters,

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 14:22

    Well, here's a possibly too simplistic of an answer..

    If with full sha1 you get about 1 in 2^160 chance of collision, then by truncating one character you increase the chances of collision by 16 (all possible values of the truncated character)... which is 2^4.. So, if you truncate x characters you get 1 in 2^(160 - 4*x) chances of collision.. right?

提交回复
热议问题