Hash Collision
문제
For security reasons, TU Delft is going to place locks with numeric keypads on the doors of a large number of rooms. Each room will have its own pass code. The task of setting up the server on which all codes will be stored is given to Harry and Sharon.
Having paid attention in cybersecurity class, they know that the codes should be passed through a hash function, preferably multiple times, before storing.
Sharon came up with the nifty idea of letting the room number be the number of times the code is passed through the hash function. That way, even if two rooms happen to have the same pass code, they will not (necessarily) end up with the same hash value. However, they find that for some combinations of room number and code, the hash value happens to be the same as the original code, presenting a security risk.
Not to be outdone by Sharon, Harry came up with an idea of his own: to switch the roles, that is, let the code be the number of times the hash function is applied to the room number. In other words, if is the code and is the room number, the hash value will be .
After some thought, Sharon claimed that, regardless of what the function is, it would always still be the case for some room numbers and codes that the hash value is the same as the code; that is, that . In fact, Sharon thinks it would not be too difficult to find two such numbers, even without knowing the full details of .
This dismissive statement made Harry angry, who believed that Sharon was just jealous of his idea. After a big argument that led nowhere, Harry decided to make Sharon prove her claim: he has written a program that, upon sending it a query, will return the hash value for the and given in the query, using a secret hash function he has chosen. The hash function accepts any in , where is given, and returns a value in the same range. The value of should also be in the same range. The challenge for Sharon is to find and such that , using a limited number of queries.
You know that Sharon is right about her claim and decide to help her.
In the first sample case, the value of is 6, and the hidden function is given by , , , , , and . In the second sample, , and , , , and .
예제
예제 1
6 3 5 4 6 2
? 2 4 ? 4 1 ? 5 5 ? 1 6 ? 2 1 ! 2 1
예제 2
4 2 4 2
? 1 3 ? 2 3 ? 3 3 ! 4 3