|
Reprinted from: http://acm.uva.es/p/v7/795.html |
|||||||||||||||||
[Converted with LaTeX2HTML 98.1 release (February 19th, 1998) originally by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds - revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan - with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others.]
Count Mathias Sandorf, a hero of Jules Verne, encrypted the secret
messages of the Trieste conspirators by using a cipher key a
6
1. Extend the message, by appending trailing `#' characters, until its length equals a multiple of 36, and then reverse the extended message. By convention, original messages do not end with # but, however, they can contain #. For example, the message:Real Programmers use Fortran. Quiche Eaters use Pascal. is 55 characters long and has to be extended by appending 17 trailing #. Right after step 1, the message is:#################.lacsaP esu sretaE ehciuQ . nartroF esu sremmargorP laeR 2. Position the cipher key on a sheet of paper, the pinch-mark facing upwards. 3. Copy the next 9 characters from the message (initially the first 9 characters) onto the paper through the holes of the cipher key, one character per hole, from left to right and top to bottom.
4. Turn the cipher key 90 degrees
clockwise and repeat from step 3 until the key gets to its
initial position, with the pinch-mark up. The result is a 6 5. Repeat from step 2 until all characters of the message are copied into coded groups, then append the rows of the coded groups from the first row of the first generated coded group to the last row of the last generated coded group, following the order of rows in each group and the order of groups. For the given message there are two coded groups, shown below,
which, when appended, yield the final encrypted message:
Input and OutputWrite a program that decrypts messages encrypted by using the Sandorf's algorithm. The encrypted messages are read from a text file, one message per line ending with a line-break. Lines can be of different length. All characters of a line (except the line-break) are part of the encrypted message which cannot exceed 108 characters. The decrypted messages are printed on the standard output file. Each output line contains a message in its original form, starting from the beginning of the line. Decoding the above encrypted message yields the result:Real Programmers use Fortran. Quiche Eaters use Pascal. Sample Inputirdetn ihtoteao pesms soiaCet snaoi
H### ##d#l##a####n##o)##Dg#(##i#n#o# Sample OutputCompetition is a disease that sooner (Donald Honig) |
|||||||||||||||||
Miguel Revilla 2001-01-05 |