Polish version    English version  
  History of OI -> XI OI 2003/2004 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
Schedule
Problems
Stage III - results
Stage II - results
Stage I - results
Stage II
Stage III
Rules
For contestants
Helpful resources
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
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:

  • ciphers cash card's number x, obtaining a number y, written hexadecimaly,
  • leaves out all but the first four hexadecimal digits of the number y,
  • converts the retained hexadecimal digits to decimal system (i.e. digit h is converted to a[h], where h=A is identified with 10, h=B with 11, h=C with 12, h=D with 13, h=E with 14, h=F with 15),
  • the 4-digit decimal number so obtained has to be identical with the PIN provided.

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))



Print friendly version