eolymp
bolt
Try our new interface for solving problems
Məsələlər

Cracking the Code

Cracking the Code

You have been contracted by a terrorist group to crack encrypted transmissions. The only information that the terrorists could give you regarding the encrypted message is that a fixed key-length \textbf{XOR}-encryption algorithm was used to encode it. After a brief search on the 'Net, you find the following definition of \textbf{XOR}-encryption: Assuming that we have a character \textbf{u\[i\]} from the unencrypted input stream, and a key \textbf{k} of length \textbf{l} with characters \textbf{k\[j\]}, \textbf{0} ≤ \textbf{j} < \textbf{l}, then the encrypted value \textbf{e\[i\]} is obtained as follows: \textbf{e\[i\] = u\[i\] XOR k\[i MOD l\]} where \textbf{MOD} is the remainder after integer division (the \textbf{\%} operator in C, C++ and Java), and \textbf{XOR} is the bitwise \textbf{XOR} operator applied to an \textbf{8}-bit character (the \textbf{^} operator in C, C++ and Java). XOR encryption is a symmetric encryption scheme, so that the message is decoded by encrypting the encrypted message (a second time) with the same key, so that \textbf{u\[i\] = e\[i\] XOR k\[i MOD l\]} You are given four encrypted input streams of \textbf{30000} characters each (that is, a continuous input stream of \textbf{120000} characters). Your program must output the four decrypted stream with no other characters embedded. The streams were encrypted using \textbf{XOR} encryption with fixed length keys of fewer than \textbf{30} characters. Each character in the key is unique (appears only once), and is selected from the set a..z merged with \textbf{0..9}. Your task is to determine the correct key length, and decrypt the encrypted input stream. Your terrorist friends provided you with one last vital piece of information: "\textbf{The decrypted message will be in English.}" It is recommended that you write an \textbf{XOR} encryption program first to aid you in testing your solution. \InputFile The output of the \textbf{XOR} encryption algorithm is not normally printable, since it may contain ASCII codes greater than \textbf{127}. Therefore, the sample-encrypted message below is shown in numerical ASCII values (in decimal) - the actual input file contains the ASCII symbols. If the message "the quick brown fox jumps over the lazy dog" is encrypted using the key "12" (the literal characters "1" and "2", concatenated), the following (binary) file results. 69 90 84 18 64 71 88 81 90 18 83 64 94 69 95 18 87 93 73 18 91 71 92 66 66 18 94 68 84 64 17 70 89 87 17 94 80 72 72 18 85 93 86 If these values are converted to ASCII symbols and stored in a file (the file length should be exactly \textbf{43} bytes), it can be used as input to your program. It is recommended that you first write the encryption algorithm. \OutputFile Your program should determine the key length to be 2 (you should not output this value), and decrypt the message to yield: the quick brown fox jumps over the lazy dog \textbf{Notice} Since it's impractical to read a binary input from a text stream, I have converted the original input data into numbers, that is, the ascii value of respective characters. So what you are really expecting is \textbf{120000} lines of numbers, one per line! It doesn't matter for the output because they should become printable characters if you ever got this mess right.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Mənbə Southern African 2001