XI Olimpiad in Informatics 2003/2004

Task: pin

PIN-code

I stage competition  
Source file: pin.xxx (xxx=pas,c,cpp)
Memory limit: 32 MB

Each cash card has a 4-digit identification number (PIN). Whether a transaction by means of a cash card will be realized or not, depends on the conformity of cash cards number and PIN. This conformity is being checked by the HSM (hardware security module). This module recieves three parameters: cash cards number x, PIN p and a conversion array a (consisting of 16 numbers between 0 and 9, indexed from 0 to 15). The HSM acts in the following way:

The standard conversion array is a=(0, l, 2, 3, 4, 5, 6, 7, 8, 9, 0, l, 2, 3, 4, 5). Suppose, for instance, the cash card's number is x = 4556 2385 7753 2239 and after having it ciphered we recieve a hexadecimal number y = 3F7C 2201 00CA 8AB3. To obtain a 4-digit PIN we take the first four hexadecimal digits (3F7C) and encode them by means of the standard conversion array. The outcome is PIN p=3572. Unfortunately, a dishonest bank employee or a computer hacker could gain access to the HSM and try to guess the PIN by manipulating the conversion array.

Task

Write a programme which will try to guess the PIN by means of queries to HSM. It can pose 30 queries at the most.

Interface description

Your programme should communicate to the 'outer world' solely by means of the functions provided by the hsm (hsm.pas in Pascal, hsm.h in C/C++). It means it cannot open any files or use the standard input/output.

Upon being activated your programme should each time guess one PIN, compatible with the cash card number known to the hsm, using standard conversion array. The hsm makes following functions available: sprawdz (check in Polish) and wynik (outcome in Polish). Their declarations in Pascal are:

function sprawdz (pin:array of Longint, a:array of Longint):Boolean;
procedure wynik (pin:array of Longint);

and in C/C++:

int sprawdz (int pin[], int a[]);
void wynik (int pin[]);

The parameters of the function sprawdz are: the PIN being investigated (in form of a four element digit array) and conversion array (consisting of 16 elements). It's outcome is a boolean value which determines whether the PIN provided is compatible with cash cards number, given the conversion array. Your programme should call the sprawdz function 30 times at the most and the wynik function exactly once. Calling the wynik procedure terminates the programme. Its parameter should be a PIN compatible with the cash cards number, given standard conversion array.

To test your solution you should write your own hsm. It is not, however, part of the solution and should not be sent alongside with the programme.

Example

A hypothetical interaction between the programme and the hsm could be as follows:

sprawdz ((1,1,1,1), (0,0,1,1,0,1,0,1,0,0,0,0,1,1,0,1)) = true
sprawdz ((1,1,0,0), (0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1)) = true
sprawdz ((1,1,0,0), (0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0)) = false
sprawdz ((1,0,0,0), (0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0)) = true
sprawdz ((0,0,1,0), (0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0)) = false
sprawdz ((0,0,0,1), (0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0)) = true
wynik ((3,5,7,2))