Editorial for Baltic OI '01 P2 - Crack the Code
Submitting an official solution before solving the problem yourself is a bannable offence.
Encryption Program
The encryption program encrypts (one by one) the successive characters from the input file. Characters that are not letters (of the English alphabet) are left unaltered. The key given by the user specifies the way characters are coded. Namely, the
Reverse Engineering Algorithm
It can be easily seen, that knowing the key we can decode the message in a similar way it was coded — we can apply the coding algorithm given above for a key consisting of negated elements of the coding key. Hence, the problem reduces to finding the coding key. In case of texts written in the natural language, the relative frequencies of particular letters are different. So, we can use some statistical methods to determine the key. Basing on the uncoded piece of text we can calculate the probability with which particular letters appear in the text.
We will denote by
We will denote by
Now, it is enough to find such a cyclic rotation of sequence
Intended Solution
Our solution is based on the method described above. We also need a measure of how
"close" the distribution
where
Remark. The test
Other Solutions
This solution differs from the one above only in the measure used to compare
probability distributions. We can view the distributions
Comments