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

Tales from DeCrypt

Tales from DeCrypt

\includegraphics{https://static.e-olymp.com/content/31/31bf9d2bf3cf978229a030c5fa4436658a57c264.jpg} In newsgroups, lists, and other ways of publicly sharing information, one popular method of obscuring information without actually hiding it has been the \textbf{ROT13} algorithm: alphabetic characters are simply rotated by \textbf{13} positions (modulo \textbf{26}), so that the encryption and decryption algorithms are identical. Messages that are potentially offensive to some readers of the newsgroup or list are purposely posted in \textbf{ROT13} form, on the theory that the reader is responsible for changing the offensive material into clear-text form, and so that the reader cannot complain about it. We can use a rotational cipher to hide information as well as obscure it. You are responsible for generating the decryption algorithm for the encryption algorithm described here. It is restricted to \textbf{7}-bit ASCII/ANSI characters, and we will deal only with the printing characters --- \textbf{0x20} (space) up to and including \textbf{0x7e} ('\textbf{~}') for \textbf{95} characters. This way the encrypted text can still be dealt with as pure text for file manipulation and transmission purposes. \textbf{Encryption Algorithm} Select three numbers to encode all the necessary information for this linear congruential random number generator: the multiplier (a), the modulus (m), and the seed (s): \textbf{double r(in int a, in int m, inout int s)} \textbf{double val = s modulo m / double(m)} \textbf{s = ( a * s + 1 ) modulo m} \textbf{return val} The two integers for the random number generator and the initial seed (s in the pseudo code above) are contained within the file as the first line, which contains three white-space delimited \textbf{32}-bit integers, given in the order "\textbf{a m s}". Range: \textbf{2} < \textbf{number} < \textbf{65536}. So a first line of "\textbf{12343 65536 11}" generates \begin{itemize} \item \textbf{a = 12343} \item \textbf{m = 65536} \item \textbf{s = 11} \end{itemize} The output file of the encryption program contains these three numbers, white-space delimited, on one line. The encrypted text begins on the next line. This constitutes the input to your decryption program. Encrypted text is generated by the following algorithm: \textbf{for each character c in the input stream} \textbf{if the character is not in the range 0x20 through 0x7e} \textbf{pass it through to the output} \textbf{otherwise} \textbf{c = ( (c -- 32) + ceiling( 95 -- r(a,m,seed)*95) ) ) modulo 95 + 32} \textbf{send c to the output} \InputFile The input for your program is the output of the encryption program: three white-space delimited numbers on one line. The encrypted text begins on the next line, and continues to the end of file. \OutputFile Your output is the decryption of the text encrypted in the input file.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
12343 65536 11
a[+d'x/vKmV<WP(+2:N]%CN+u#rjNQB
vW'ecvzcK5E%F;^Qlo~pt\]kwGr*.yv|
So|#p36LhPNM#"N<I|}2c[cGX5I3o!u
m48rOK1&N=&8%Q-2Jq^[v&r;at"z#'C
Çıxış verilənləri #1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccccccccc
ddddddddddddddddddddddddddddddd
Mənbə ACM ICPC North America - Pacific Northwest 2010