Question: Explanation for the Python class: x 1 and x 2 are messages: x 1 = Bob sends 1 0 to Oscar's account x 2 =
Explanation for the Python class: x and x are messages: x "Bob sends to Oscar's account" x "Bob sends to Oscar's account" For x and x Oscar wants to create two messages m and m that satisfy the following properties: hashm hashmthe implemented hash function below, called h Semantic meaning of original messages x and x must be preserved. In other words, m and m should look like x and x respectively. Hint: You can create such messages by appending invisible characters spaces and tab to the original messages. This is what I have been attempting to do The collision search must be effective. According to the argument of birthday attack, the number of messages you need to generate until the first collision found is On where n is the number of hash output bits. The output bits I am testing with are and The expected outputs are listed below Expected Output: elapsed time in seconds: Bob sends to Oscar's account Whitespace tabs following with a period after them Bob sends to Oscar's account whitespace and tabs following with a period after them True Given already completed portion of the Class is not to be edited or changed!: import time class Collision: slotsHH "outputbits", "modulus", "hashfunc" def initself outputbits, hashfunc: self.H self.H self.outputbits outputbits self.modulus pow outputbits self.hashfunc hashfunc def hself x: return self.hashfuncx
My code:
import time
class Collision:
slotsHH "outputbits", "modulus", "hashfunc"
def initself outputbits, hashfunc:
self.H
self.H
self.outputbits outputbits
self.modulus pow outputbits
self.hashfunc hashfunc
def hself x:
return self.hashfuncx self.modulus
def searchself x x depth:
hash self.hx
hash self.hx
if hash hash:
return x x
if depth :
# Recurse on x and x
collision self.searchx x depth
if collision:
return collision
# Recurse on xt and xt
return self.searchxt xt depth
# If depth limit reached
return None
def confirmCollisionself m m:
hash self.hm
hash self.hm
return hash hash and hash in self.H and hash in self.H
def main:
outputbits # try or first
x "Bob sends $ to Oscar's account"
x "Bob sends $ to Oscar's account"
collision Collisionoutputbits, hash # Python hash funciton is used, though any hash functions should work
start time.time
result collision.searchx x
end time.time
if result:
m m result
printelapsed time in seconds:", end start
printm
printm
printcollisionconfirmCollisionm m
else:
printNo collision found within the depth limit
if namemain:
main
The only thing that can be modified is search and main in order to complete the collision search with a depth of it should take around seconds to complete
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
