New PB
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
# COMP6441-birthday-attack
|
||||
|
||||
Birthday attack demo for COMP6441: https://webcms3.cse.unsw.edu.au/COMP6441/24T3/resources/103020
|
||||
|
||||
Current PB: last 10
|
||||
Known best: last 12
|
||||
30
confession_fake.txt
Normal file
30
confession_fake.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
This is the secret confession of Richard Buckland
|
||||
to be revealed by anonymous email if I should
|
||||
mysteriously vanish. I have left the last few hex
|
||||
digits of the SHA256 hash of this message with my
|
||||
trusted solicitor, Dennis Denuto, which will verify
|
||||
that this is indeed my intended and unaltered
|
||||
confession written by me Richard Buckland.
|
||||
|
||||
Dennis has not seen this confession he has only seen
|
||||
the last few digits of the hash. I have also sent copies
|
||||
of the last few digits to my bank manager and to my priest
|
||||
Father Brown.
|
||||
|
||||
On the 10th of February I saw Mark Zukerberg near my
|
||||
house and we struck up a conversation. He explained all
|
||||
the things he was doing to ensure that Facebook respects
|
||||
privacy - both of its users and of others. It was very
|
||||
impressive.
|
||||
|
||||
I feel awful that I have been criticising Facebook publicly
|
||||
for so long. I apologised to him in our conversation and
|
||||
now I want to confess to the world that actually Facebook
|
||||
has more than enough privacy features, and that the reason
|
||||
I spend so much time criticising Facebook is that I am
|
||||
envious of Mark and wish I was a clever and smart and wise
|
||||
as he is. I feel so bad for having been so mean to him for
|
||||
so many years that I am considering retreating to the outback.
|
||||
I may well cut off all contact with the world and live as a
|
||||
hermit from now on. So do not worry if I vanish it is just
|
||||
that I feel so guilty that I have been so unfair to Facebook.
|
||||
30
confession_fake.txt.out
Normal file
30
confession_fake.txt.out
Normal file
@@ -0,0 +1,30 @@
|
||||
This is the secret confession of Richard Buckland
|
||||
to be revealed by anonymous email if I should
|
||||
mysteriously vanish. I have left the last few hex
|
||||
digits of the SHA256 hash of this message with my
|
||||
trusted solicitor, Dennis Denuto, which will verify
|
||||
that this is indeed my intended and unaltered
|
||||
confession written by me Richard Buckland.
|
||||
|
||||
Dennis has not seen this confession he has only seen
|
||||
the last few digits of the hash. I have also sent copies
|
||||
of the last few digits to my bank manager and to my priest
|
||||
Father Brown.
|
||||
|
||||
On the 10th of February I saw Mark Zukerberg near my
|
||||
house and we struck up a conversation. He explained all
|
||||
the things he was doing to ensure that Facebook respects
|
||||
privacy - both of its users and of others. It was very
|
||||
impressive.
|
||||
|
||||
I feel awful that I have been criticising Facebook publicly
|
||||
for so long. I apologised to him in our conversation and
|
||||
now I want to confess to the world that actually Facebook
|
||||
has more than enough privacy features, and that the reason
|
||||
I spend so much time criticising Facebook is that I am
|
||||
envious of Mark and wish I was a clever and smart and wise
|
||||
as he is. I feel so bad for having been so mean to him for
|
||||
so many years that I am considering retreating to the outback.
|
||||
I may well cut off all contact with the world and live as a
|
||||
hermit from now on. So do not worry if I vanish it is just
|
||||
that I feel so guilty that I have been so unfair to Facebook.
|
||||
22
confession_real.txt
Normal file
22
confession_real.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
This is the secret confession of Richard Buckland
|
||||
to be revealed by anonymous email if I should
|
||||
mysteriously vanish. I have left the last few hex
|
||||
digits of the SHA256 hash of this message with my
|
||||
trusted solicitor, Dennis Denuto, which will verify
|
||||
that this is indeed my intended and unaltered
|
||||
confession written by me Richard Buckland.
|
||||
|
||||
Dennis has not seen this confession he has only seen
|
||||
the last few digits of the hash. I have also sent copies
|
||||
of the last few digits to my bank manager and to my priest
|
||||
Father Brown.
|
||||
|
||||
On the 10th of February I saw Mark Zukerberg peeping
|
||||
through my window and recording my private and personal
|
||||
conversation with my friend.
|
||||
|
||||
I confronted him and he was very embarrassed. He
|
||||
promised to pay me $1 million a year if I would stay
|
||||
silent and not tell anyone I had seen him do this. I
|
||||
agreed but now I worry that it would be cheaper for him
|
||||
to make me vanish than to keep paying me.
|
||||
22
confession_real.txt.out
Normal file
22
confession_real.txt.out
Normal file
@@ -0,0 +1,22 @@
|
||||
This is the secret confession of Richard Buckland
|
||||
to be revealed by anonymous email if I should
|
||||
mysteriously vanish. I have left the last few hex
|
||||
digits of the SHA256 hash of this message with my
|
||||
trusted solicitor, Dennis Denuto, which will verify
|
||||
that this is indeed my intended and unaltered
|
||||
confession written by me Richard Buckland.
|
||||
|
||||
Dennis has not seen this confession he has only seen
|
||||
the last few digits of the hash. I have also sent copies
|
||||
of the last few digits to my bank manager and to my priest
|
||||
Father Brown.
|
||||
|
||||
On the 10th of February I saw Mark Zukerberg peeping
|
||||
through my window and recording my private and personal
|
||||
conversation with my friend.
|
||||
|
||||
I confronted him and he was very embarrassed. He
|
||||
promised to pay me $1 million a year if I would stay
|
||||
silent and not tell anyone I had seen him do this. I
|
||||
agreed but now I worry that it would be cheaper for him
|
||||
to make me vanish than to keep paying me.
|
||||
80
enforcer.py
Normal file
80
enforcer.py
Normal file
@@ -0,0 +1,80 @@
|
||||
from multiprocessing import Pool
|
||||
from hashlib import sha256
|
||||
|
||||
# Function to calculate the hash for the given modified file content
|
||||
def calculate_hash(file_lines, num_chars):
|
||||
return sha256("\n".join(file_lines).encode()).hexdigest()[-num_chars:]
|
||||
|
||||
# Function to generate a modified file by adding spaces based on the bit pattern
|
||||
def modify_and_hash(args):
|
||||
real_og, fake_og, num_chars, bit_pattern = args
|
||||
|
||||
# Modify the real and fake files based on the bit pattern
|
||||
real_modified = [
|
||||
line + " " * ((bit_pattern >> idx) & 1)
|
||||
for idx, line in enumerate(real_og)
|
||||
]
|
||||
fake_modified = [
|
||||
line + " " * ((bit_pattern >> idx) & 1)
|
||||
for idx, line in enumerate(fake_og)
|
||||
]
|
||||
|
||||
# Calculate hashes for both modified files
|
||||
real_hash = calculate_hash(real_modified, num_chars)
|
||||
fake_hash = calculate_hash(fake_modified, num_chars)
|
||||
|
||||
return (real_hash, fake_hash, real_modified, fake_modified)
|
||||
|
||||
def main(real_file, fake_file, num_chars):
|
||||
# Read the original files
|
||||
with open(real_file) as f:
|
||||
real_og = f.read().splitlines()
|
||||
with open(fake_file) as f:
|
||||
fake_og = f.read().splitlines()
|
||||
|
||||
all_real_hashes = {}
|
||||
all_fake_hashes = {}
|
||||
|
||||
found_collision = False
|
||||
|
||||
# Use multiprocessing Pool
|
||||
with Pool() as pool:
|
||||
i = 0
|
||||
while not found_collision:
|
||||
# Prepare a batch of bit patterns to process in parallel
|
||||
batch_size = 100 # Number of combinations to process in parallel
|
||||
bit_patterns = [(real_og, fake_og, num_chars, pattern) for pattern in range(i, i + batch_size)]
|
||||
|
||||
# Process the batch in parallel
|
||||
results = pool.map(modify_and_hash, bit_patterns)
|
||||
|
||||
# Check the results for a hash collision
|
||||
for real_hash, fake_hash, real_modified, fake_modified in results:
|
||||
all_real_hashes[real_hash] = real_modified
|
||||
all_fake_hashes[fake_hash] = fake_modified
|
||||
|
||||
if real_hash in all_fake_hashes or fake_hash in all_real_hashes:
|
||||
collision_hash = real_hash if real_hash in all_fake_hashes else fake_hash
|
||||
print(f"Collision found! {real_file}.out and {fake_file}.out have the same hash: {collision_hash}")
|
||||
|
||||
with open(f"{real_file}.out", 'w') as f_out:
|
||||
f_out.writelines("\n".join(all_real_hashes[collision_hash]))
|
||||
with open(f"{fake_file}.out", 'w') as f_out:
|
||||
f_out.writelines("\n".join(all_fake_hashes[collision_hash]))
|
||||
|
||||
found_collision = True
|
||||
break
|
||||
|
||||
i += batch_size
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) != 4:
|
||||
print(f"Usage: {sys.argv[0]} <real_file> <fake_file> <num_chars>")
|
||||
sys.exit(1)
|
||||
|
||||
real_file = sys.argv[1]
|
||||
fake_file = sys.argv[2]
|
||||
num_chars = int(sys.argv[3])
|
||||
|
||||
main(real_file, fake_file, num_chars)
|
||||
Reference in New Issue
Block a user