Member-only story
It’s Your Cybersecurity Birthday!
I love giving live cybersecurity demos, and it’s great when they work well. Apart from hacking dolls, kettles, weighing scales, and CCTV cameras, my favourite demos are related to cryptography. This includes demonstrating the RSA and Diffie-Hellman method live, but my favourite one is to perform the birthday attack for hash collisions. For this, if I have a class of 60, I am 99.41% sure that I will be successful in finding two students with the same birthday, and even with 23 students in the class, I have around a 50/50 chance of finding two students with the same birthday. For this, I need to match the same day and month of the birthday (and not the year).
So how does this happen? Well, let’s imagine we have a bag of balls numbered 1 to 365, and where these numbers could represent the days of the year. I will take out a ball and note the number, and then put it back in the bag. The challenge is now to know, on average, how many attempts it will take me before I draw a number which has appeared before.
So let’s try this program to estimate how many students I need:
import random
days=365
array=[]
for i in range(1,days):
x=random.randint(1,days)
if (x in array):
print(f"Duplicate found at {i}")
break
array.append(x)
print(x, end =" ")