哈希碰撞(hash collision)

优秀的密码学课

https://classroom.udacity.com/courses/cs387/lessons/48683850/concepts/487362180923 

 

# HW2-5 Version 2
#
# In this assignment your job is to write a function, find_collision,
# that finds a hash collision for any given input message.
#
# The input message will be at least four blocks (64 characters) long.
#

from Crypto.Cipher import AES
from copy import copy

# Remember, this is NOT secure cryptology code
# This is for fun and education.  Do not use this
# to protect the classified files from Area 51

def find_collision(message):
    new_message = copy(message)
    ####################
    # START YOUR CODE HERE
    def cacluate(m0,m1,c0,c1):
        e0 = xor_bits(m0,c0)
        e1 = xor_bits(m1,c1)
        
        return xor_bits(e0,c1),xor_bits(e1,c0)
        
    block_size, block_enc, key, ctr = hash_inputs()
    
    cipher = counter_mode(message, key, ctr, block_size, block_enc)
    m0 = get_block(message,0,block_size)
    m1 = get_block(message,1,block_size)
    c0 = get_block(cipher,0,block_size)
    c1 = get_block(cipher,1,block_size)
    new_m0, new_m1 = cacluate(m0,m1,c0,c1)
    
    new_message[0:block_size] = new_m0
    new_message[block_size:block_size*2] = n
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值