Update birthday_attack.py
This commit is contained in:
@@ -2,23 +2,20 @@ import hashlib
|
|||||||
import os
|
import os
|
||||||
import binascii
|
import binascii
|
||||||
|
|
||||||
nr_collisions = 0
|
nr_collisions, hashed_dict, strn_table, n = 0, {}, {}, 10
|
||||||
hashed_dict = {}
|
|
||||||
strn_table = {}
|
|
||||||
n = 1
|
|
||||||
file = open("results.txt", "w")
|
file = open("results.txt", "w")
|
||||||
while n < 11:
|
while n:
|
||||||
strn = binascii.b2a_hex(os.urandom(16))
|
strn = binascii.b2a_hex(os.urandom(16))
|
||||||
hashed_strn = hashlib.md5(strn).hexdigest()
|
hashed_strn = hashlib.md5(strn).hexdigest()
|
||||||
sliced_hash = hashed_strn[:n]
|
sliced_hash = hashed_strn[:10]
|
||||||
if sliced_hash in hashed_dict:
|
if sliced_hash in hashed_dict:
|
||||||
nr_collisions += 1
|
nr_collisions += 1
|
||||||
x = "----------------------------------------------------------------------------------"
|
x = "-----------------------------------------------------------------------------------"
|
||||||
z = "Collision number: " + str(nr_collisions) + " "*n + "Collision: " + str(sliced_hash)
|
z = "Collision number: " + str(nr_collisions) + " " * 18 + "Collision: " + str(sliced_hash)
|
||||||
a = "Hashes: " + " "*(n-7) + str(hashed_dict[sliced_hash]) + " " + str(hashed_strn)
|
a = "Hashes: " + " " * 10 + str(hashed_dict[sliced_hash]) + " " + str(hashed_strn)
|
||||||
b = "Values: " + " "*(n-7) + strn.decode() + " " + strn_table[sliced_hash].decode()
|
b = "Values: " + " " * 10 + strn.decode() + " " + strn_table[sliced_hash].decode()
|
||||||
file.write(x + "\n" + z + "\n" + a + "\n" + b + "\n")
|
file.write(x + "\n" + z + "\n" + a + "\n" + b + "\n")
|
||||||
n += 1
|
n -= 1
|
||||||
else:
|
else:
|
||||||
hashed_dict[sliced_hash] = hashed_strn
|
hashed_dict[sliced_hash] = hashed_strn
|
||||||
strn_table[sliced_hash] = strn
|
strn_table[sliced_hash] = strn
|
||||||
|
|||||||
Reference in New Issue
Block a user