ENIGMAS - Enigma Machine

This challenge is to simulate the three rotor M3 Enigma Machine. For each test three lines of information will be provided; the first line will contain the rotor settings, the second the plugboard, and the third will be the text to encode/decode with the Enigma cipher.

Input

The first line will contain a single value T, for the number of tests to follow, where T <= 100.

For each test there will be three lines:

  • The first line will contain three entries indiciating: the Walzenlage, the Ringstellung, and the Grundstellung in the form '123 AAA BBB'. The Walzenlage only contains numbers 1-5. The Ringstellung and Grundstellung will be provided as triplets of letters in the range A-Z.
  • The second line will contain pairs of letters, from the range A-Z, indicating the settings for the Steckerbrett - there may be up to 13 pairs of letters.
  • The final line of the test will contain an unknown length message to encode/decode - the message will be in the standard quintuple form used at the time, separated with spaces, eg 'ABCDE FGHIJ KL'. The final group may be 1-5 letters in length. Again, only the range of letters A-Z will be used. The line will be terminated in a newline ('0x0A').

The Enigma machine used is the three rotor M3 version. This had five rotors, of which only three would have been installed at any time. The Umkehrwalze in use is the 'B' wiring.

Output

The output is to match the third line of the input, i.e. must be in the same quintuple grouping. One line of output per message is to be produced.

Example

Input:
2
123 JAN DER
2 123 JAN DER SP OJ RU LZ THISX ISXAN XEXAM PLEXI NPUT 543 SPO JPL SH OR TE NI YUQKD YVPSF HCQEI VHAPE NAQZQ I
SP OJ RU LZ
YUQKD YVPSF HCQEI VHAPE NAQZQ I
Output:
SJLKM SVZYM HXTUW VVWYY EDEB
THISX ISXAX DECOD XEDXM ESSAG E

Added by:Jander
Date:2012-10-04
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:http://en.wikipedia.org/wiki/Enigma_machine

hide comments
2012-10-19 07:26:31 Jander
I posed this challenge for the SHORTEN contest, but decided to open it up to main Spoj.

I want the scoring to be based on code length, not time, as it's about simplifying the Enigma machine, not about speeding it up. I concur that based on that rationale behind the scoring it ought to be in Challenge, not Classical so I'll move it.

Edit: Moved to Challenge.

Last edit: 2012-10-19 07:26:56
2012-10-19 07:26:31 numerix
I agree with legrand.
2012-10-19 07:26:31 legrand
The problem is a real simulation problem, not so simple. I don't think it should move to the challenge section and the scoring should be based on time, not the codelength.

Last edit: 2012-10-18 12:56:39
2012-10-19 07:26:31 numerix
@legrand: I suppose it's the length of your code as it is a problem made for Shortening Contest. So either scoring should be changed or problem should be moved to challenge section.
2012-10-19 07:26:31 Boopathi Rajaa
Good one ... Got AC :).

EDIT: And the scoring should be based on time, not the length of the code. :-/

Last edit: 2012-10-18 15:26:47
2012-10-19 07:26:31 legrand
I've AC. good problem.

Last edit: 2012-10-17 14:45:54
2012-10-19 07:26:31 Asheesh Ranjan
Nice problem.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.