优秀的密码学课
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