Hello there! Welcome to the first post on this blog.

In this post, we will understand what is popularly known as “The Birthday Paradox” and along with that, we will look into what this paradox means in cryptography, where the birthday paradox is known as the birthday attack.

**Prerequisites**

You will need to know the basics of combinatorics & probability theory to understand this article.

## Assumptions

For the first part of the article, we also assume that birthdays are distributed uniformly across the year i.e. an equal number of people are born on all days of the year. This assumption is not even close to true, but to begin, it will make it easy to understand the calculations. We will also see what happens when the distribution is not uniform.

**The answer**

The probability that at least two people have the same birthday with people is at least . The reason this is called a paradox is that the number looks so small compared to the number of days in a year i.e. days, but still, the probability of at least two people having the same birthday is as high as . These values are calculated with the assumption of uniform distribution and if the distribution is non-uniform, the probability will be higher than .

Next, let’s see how we get this answer. I would highly recommend that you try to solve the problem yourself before you start reading the next section. You can also start reading the solution, and whenever you feel you can do the rest of the process yourself, feel free to stop reading and continue on your own.

**Solution**

Let’s think of the problem this way, we have people and we have to assign a birthday between and (days of the year) to each of them. We can define the probability that at least two people will share the birthday

(We can only use this formula when the probability distribution for the values is uniform.)

For every person, we have possible values and so the total number of possible combinations of the values that the people can take is .

Now, out of these combinations, we need the number of combinations where at least two people have the same birthday. To calculate that, we will calculate the number of combinations where no one shares the birthday with anyone else i.e. every person is assigned a different birthday and then subtract this number from the total number of combinations.

Number of combinations where no two people share the birthday

So, the number of combinations where at least two people share the birthday will be

Using the above formula, the final probability will be

Simple! Wasn’t it? This paradox works because intuitively we try to compare the number of people with the number of days in a year. Instead, we should be comparing the number of possible pairs which is quite high even with relatively fewer people.

**But birthdays are not uniform…**

We have got the answer to the question we posed, but it works only if the given distribution is uniform. Now, we’ll see what to do if the birthday distribution is not uniform. Let’s start with the notations we will now use:

– Total number of days

– day of the year

– Probability that a person is born on

– Total number of people

– person from the group

– Probability that in a group of q people, and considering N days in a year, at least two people will share the birthday for the given distribution

For any probability distribution, data will be given like –

The data will specify the probability that a person is born on that day for every day of the year. In case of uniform distribution, all these probabilities become equal to . Let’s say the name of distribution given to us is .

The probability that the ‘s birthday lies on a specific day is given in the data, say . Let’s take another person where , the probability that is born on and is also born on the same day = (Because birthday’s are independent)

The probability that the birthday of both the people lie on the same day (any day of the year) = probability for the first day + probability for the second day + … probability for the day

The probability that and will have the different birthday

This is the probability that a given pair have the different birthday.

Total number of pairs in the group of q people

Probability that all the pairs have different birthdays,

The probability that at least one pair will have the same birthday for the given distribution ,

If we put dist as uniform distribution where for all values of .

Using the formula derived, for uniform distribution

Which will yield the same answer as before for and i.e.

Let’s see the graph for different values of and

**Observations**

1. The probability that at least two people will have the same birthday is with just 70 people in the group.

2. The probability that at least two people will have the same birthday is minimum if the birthday distribution is uniform. For a non-uniform distribution, the probability is higher. This comes with the fact that value of will be minimum if (Proof here)

3. If we put then, the value of will be in case of uniform distribution

The third observation is a bit non-trivial and works on certain approximations. Let’s work it out.

For large values of q,

For small values of x,

Using these approximations, for uniform distribution,

Putting ,

This is what we saw in the above case as well i.e. for , , we get the probability very close to . This has some implications in the real world and we will see one next.

**Breaking the hash function**

In cryptography, the birthday paradox is used to analyze the time complexity of the generic attack to find the collisions for a hash function. The final aim is to find two inputs which will have the same output for the given hash function. The generic attack is to keep evaluating the hash function on different inputs until we find a collision. What will be the time complexity of this attack?

Assuming that the hash function outputs bits, the total number of possible outputs for the function

By the pigeonhole principle, by evaluating the function at different inputs, we will find a collision for the hash function with probability . According to this analysis, the time complexity to find a collision will be .

Now, If we compare this problem with the birthday paradox we discussed above, we can compare the inputs to the hash function with the people and compare the outputs of the hash function with the birthdays. As per our observation above, if we evaluate the function at values, we will be able to find a collision with the probability .

So, if we evaluate the function at different inputs in a single iteration to find the collision with probability , the expected number of iterations required to find a collision will be .

And so the time complexity to find a collision for a given hash function will be which shows the significant reduction in the number of function evaluations we will need to make to find a collision for a given hash function.

Thank you for reading ðŸ™‚

**References**

1. Jonathan Katz and Yehuda Lindell. 2007. Introduction to Modern Cryptography (Chapman & Hall/Crc Cryptography and Network Security Series). Chapman & Hall/CRC.

2. How to prove the sum of squares is minimum?

3. Birthday Problem on Wikipedia