ch54.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:matasano 作者: shainer 项目源码 文件源码
def GenerateCollisionTree(k, stateLen):
    nodesByLevel = collections.defaultdict(list)

    allBytes = range(2 ** 8)
    allPossibleBlocks = []
    for comb in itertools.combinations(allBytes, stateLen):
        byteString = b''.join(x.to_bytes(1, 'little') for x in comb)
        allPossibleBlocks.append(byteString)

    for level in range(k+1):
        nodes = []

        if level == 0:
            nodes = RandomUniqueStates(2 ** k, stateLen)
        else:
            nodes = FindCollisions(nodesByLevel[level-1], allPossibleBlocks, stateLen)
        print('Generated nodes for level %d: %s' % (level, str(nodes)))
        nodesByLevel[level] = nodes

    return nodesByLevel

# Now I generate a meaningful message, crafted so that it's exactly 1 block
# length, but there is no need to do so. Nobody should be seeing this
# message, only the hash.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号