Baltic OI '01 P2 - Crack the Code

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem types
Baltic Olympiad in Informatics: 2001 Day 1, Problem 2

Cryptography is the science and technology of coding messages so that only the intended recipient can read them. Cryptanalysis, on the other hand, is the science of breaking the codes. For this problem, assume you're a cryptanalyst hired to break open a series of encrypted messages captured in a police raid to the headquarters of the local mafia. Your colleagues have already reverse engineered the encryption program (see attachments below), and the only thing left to do is to guess the key used to encrypt the files and reverse the algorithm.

Along with the encrypted files, there are also some plaintext files that originate from the same source as the encrypted files and thus have similar structure in terms of language, word usage, etc.

The attached folder below contains the encryption programs implemented in Pascal and C (crack.pas and crack.c). The pseudocode of these programs is shown below.

File finfoutfin stores original text, fout stores the encrypted resultalphabet[025]{A, B, C, , Z}upper-case english alphabetlen10,k0key[0len1] input integer array of size lenwhile  not at the end of fin  doc read character from finif  alphabet contains c  thenshift c by key[k]pposition of c in alphabetcalphabet[(p+key[k])mod26]k(k+1)modlenend ifprint  c to foutend while

Your task is to decrypt the given messages in the attached folder below with the help of the text of same the origin.

Constraints

1t5

All letters in the encrypted text files are upper-case.

Input Specification

You are given five data sets.

The input contains one integer t, identifying the number of the current test case.

The data set for test case t consists of the following files:

  • t.in, the encrypted message (fout in pseudocode),
  • t.txt, the plaintext file of the same origin as the encrypted message.

For example, if t=3, the encrypted message can be found in 3.in and the text of the same origin can be found in 3.txt.

All data set files along with the encryption programs are found in the attachment below.

Output Specification

Decrypt the encrypted message in the file t.in, and output the original message (fin in pseudocode).

Attachment Package

The input files are available here.


Comments

There are no comments at the moment.