What are the chances that two messages have the same MD5 digest and the same SHA1 digest?

前端 未结 5 1877
时光取名叫无心
时光取名叫无心 2021-02-01 12:51

Given two different messages, A and B (maybe 20-80 characters of text, if size matters at all), what is the probability that the MD5 digest of A is the same as the MD5 digest of

5条回答
  •  情深已故
    2021-02-01 13:23

    Generally, when one picks N elements randomly it is easier to compute the expected number of collision than the probability of a collision. Since the expected number of collisions cannot be smaller than the probability of a collision it can frequently be used as a suitable upper bound.

    Assume that p is the probability that two randomly picked elements collide. If we pick N random elements then there are N*(N-1)/2 pair of elements and hence the expected number of collisions is

    p * N * (N-1)/2.

    E.g., if we assume that the probability for a collision for both MD5 and SHA1 is p=2-288 then even after randomly picking 2100 elements we still only expect about 2-89 collisions.

    Another example: if we pick 230 random elements and only compute the MD5. Assuming that a collision between two MD5 hashes is p=2-128 this gives an expected number of 2-59 for the number of collisions. Hence even the probability that the MD5 hash collides for two inputs is already very small.

提交回复
热议问题