【问题标题】:How to find a collision of first 56 btis for MD5(MD5(x)) for input data with the same prefix?对于具有相同前缀的输入数据,如何找到 MD5(MD5(x))的前 56 个 btis 的冲突?
【发布时间】:2020-08-09 22:48:14
【问题描述】:

我有一个代码来查找哈希函数的前 56 位的冲突:md5(md5(x))(使用 Floyd 算法查找循环)。 该脚本返回发生碰撞的两个字符串(野兔、乌龟)。 如何修改此脚本以返回具有相同前缀的“hare”和“turtle”?

例如:

野兔 = 'myprefix11233...'

乌龟 = 'myprefix37008...'

例子:

MD5(MD5('myprefix11233...')) = 0x66545ea223fe91a8747a0...

MD5(MD5('myprefix37008...')) = 0x66545ea223fe91a874da5...

import hashlib

def hash(plain):
    temp = hashlib.md5(plain).hexdigest()
    bytes = []
    temp = ''.join(temp.split(" "))
    temp
    for i in range(0, len(temp), 2):
        bytes.append(chr(int(temp[i:i+2], 16)))
    first_hash = ''.join(bytes)


    return hashlib.md5(first_hash).hexdigest()[:14]


def floyd(hash, x0):
    tortoise = hash(x0)
    hare = hash(hash(x0))

    counter = 0
    final = ""
    print("first while")

    while (tortoise != hare):
        tortoise = hash(tortoise)
        hare = hash(hash(hare))

        counter += 1
        if(counter % 10000000 == 0):
            print(counter)

    tortoise = x0

    print("second while")
    counter = 0

    while (tortoise != hare):
        tortoise = hash(tortoise)
        hare = hash(hare)

        counter += 1
        if(counter % 10000000 == 0):
            print(counter)

        if (tortoise != hare):
            temp_tortoise = tortoise
            temp_hare = hare
            pass

        if (hash(tortoise) == hash(hare)):
            print("found hashes")
            print("tortoise", temp_tortoise)
            print("hare", temp_hare)
            final = 'tortoise: ' + temp_tortoise + "\n" + "hare: " + temp_hare
            with open('hashes.log', 'w') as file_:
                file_.write(final)
            break

    print("checking calculations...")
    print("tortoise", temp_tortoise, ">", hash(temp_tortoise))
    print("hare", temp_hare, ">", hash(temp_hare))

floyd(hash, 'init_data')

【问题讨论】:

    标签: python md5 hash-collision floyd-warshall floyd-cycle-finding


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    相关资源
    最近更新 更多