Scam
Difficulty: ⭐⭐⭐
This is a security question.
The Game
Tim is trying to scam people of bitcoin on the internet. He is doing this by running a challenge. People have got to try and guess the answer to a question. If they don't guess correctly he wins.
My favourite number is: _
Tim is going to scam people by having two answers to the question, and he'll reveal the real answer second.
To prove to people that he has the right answer, he first hashes his answer and posts it publically on the internet. Then, he allows the challenge to run for a week. Each person should try to guess the number, and then will hash their answer to see if they have the right answer.
You are Tim
Your job is to find two answers to the question that share the same hash. Now, since we will use MD5 to hash and finding duplicate hashes is very hard, treat the two hashes as a match if they have the same first 12 characters in the hash.
You must hash the entire sentence, not just the number.
For example:
My favourite number is: 25874428
78a7dcde58c5b4d28f3acdfb4cf9741f
And another answer
My favourite number is: 20609915
78a7dcde58c53d7b58f7b28da16f793c
- Notice how the first 12 characters are the same.
- A solution to this question would then be 25874428 and 20609915.
The example above is real. Your job is to find another one. I deliberately started at a random high number in the example. Your code can just start searching from 0 if you want.
Your program must find two integers that satisfy the requirements. You are not required to be able to play the scam. Use a birthday attack to try and find some matches.
Useful Functions
Some useful functions for this task are:
hashlib.md5()(import hashlibfirst)_Hash.hexdigest()(Method. On the return result of above)str.encode()(Encode method on strings)
Regarding Security
The hashing algorithm of MD5 is considered broken because it is easy to generate two hashes that are completely identical with a bit of understanding of how the algorithm works. For this reason, MD5 is generally avoided. It is much more common to see SHA256 being used.
This challenge does not expose this flaw. I chose MD5 because it is included in base python. SHA256 requires external libraries to use. If you wanted to use a secure hashing function, then it is important to research the currently accepted hashing algorithms. It's also important that you don't try to implement them yourselves. Use a trusted library.