-7
0
A substitution cipher is an encoding method where each letter in the alphabet is replaced with a fixed, different one; for example, given the following substitution map:
abcdefghijklmnopqrstuvwxyz
||
qwertyuiopasdfghjklzxcvbnm
The phrase "we all love cryptography" would be encoded as "vt qss sgct eknhzgukqhin".
The program will continuously read its input, one line at time; the first line will contain the substitution map, in the form of all 26 letters, in any order, without repetitions, missing letters or extraneous characters; it will be interpreted as "the first letter is the substitution for A, the second letter is the substitution for B [...] the 26th letter is the substitution for Z"; no output will be provided after reading it. For each subsequent line, the program will output the encoded text corresponding to the line. Only letters will be encoded; numbers, symbols and whitespaces will be simply copied to the output.
For simplicity, all input (including the substitution map) will only contain lowercase characters.
Sample input:
qwertyuiopasdfghjklzxcvbnm
hello
bye!
i don't know.
Sample output:
itssg
wnt!
o rgf'z afgv.
As usual, the shortest solution wins.
Additional clarifications on input:
- The program must read its input stream (I thought that was clear); command line parameters, files, named pipes, network sockets, quantum entanglement or extra sensorial perceptions are not allowed.
- The input must include only the actual text to be processed; quotes, brackets, commas or any other symbol, if found, should simply be copied to the output as they are.
- No additional characters should be required in the input. If your program requires the input text to be placed in quotes, brackets, commas or any other delimiter, then You Are Doing It Wrong (TM).
- "Line" is defined as a string of characters followed by a newline; the actual implementation of "newline" if usually left to the OS, but if you need to go into its details, just use whatever you prefer.
- An empty line is no special case; the program could either print an empty line or do nothing, but it should not print any actual text, crash, exit, destroy the operating system, set fire to the house, collapse the Sun in a black hole, summon demons from other planes of existence or replace your toothpaste with mayonnaise.
- There is no requirement for the program to run interactively; it's free to suck all its input in and then print all its output; there is also not any time limit on its execution, although it would be definitely preferable for it to terminate before the heat death of the universe.
Exiting with crash (after producing the correct output) is allowed by default. Does your edit "should not crash" rule that out? Because in that case you may be breaking some already posted answers. Also, I suggest you remove the black-hole and toothpaste stuff, as it adds nothing to the challenge – Luis Mendo – 2016-04-16T00:54:00.503
1@LuisMendo If the program exits with a crash after the input is exhausted and the correct output is procuced, then yes, it's ok. – Massimo – 2016-04-16T00:56:19.220
I thought the input format was specified very clearly; I didn't know it's considered usual practice here to rearrange input as needed. However, I saw the question lose several points after some people complained about the rules on the input format, so clearly someone got quite upset on this. Sorry, I didn't mean any harm. – Massimo – 2016-04-16T02:30:32.067
But please, when a question *clearly specifies* the input format for the required program, just don't go assuming you can change it at will... and then complain if your answer is rejected. – Massimo – 2016-04-16T02:31:05.603
11
@Massimo Arbitrarily overriding the defaults by not allowing a function and requiring a cumbersome input format are both considered things to avoid. The rules are ultimately up to you, but don't be surprised to get downvotes if your the community believes your challenge needlessly restricts participation. Note that some languages simply cannot do IO loops.
– xnor – 2016-04-16T04:25:28.7236@Massimo Furthermore, saying thing like "If your program requires the input text to be placed in quotes, brackets, commas or any other delimiter, then You Are Doing It Wrong (TM)" is needlessly confrontational and contrarian, as the community has discussed and decided to allow such things in general. Again, you can override them, but expect a poor reaction, as there seems to be no good reason. Perhaps you have experience with other golfing sites that do expect exact inputs, but that's not how we work around here. I suggest you stick around a bit and get a sense of the usual rules and culture. – xnor – 2016-04-16T04:28:59.680
You don't have to quit. Making good questions is hard, but you can still answer them. Also, I wonder why nobody's mentioned the sandbox, where you can post questions and get comments. So yeah, pull out your compiler/interpreter/whateverer and get golfing!
– CalculatorFeline – 2016-04-16T20:26:42.280@CatsAreFluffy I seriously didn't mean any harm, nor I wanted to start discussions or flame wars; I simply posted a challenge question like there are many... starting an argument about I/O formats was exactly not what I was looking for. This is definitely not the experience I was expecting from this site. – Massimo – 2016-04-16T20:39:21.807
7
Hi Massimo, sorry your first experience as a challenge author was so negative. As you've noticed, the community has grown accustomed to certain freedoms regarding I/O, submission format, etc. It's one of the not-so-obvious facets of this site that unfortunately adds another hurdle to writing a challenge. We have a Sandbox for Proposed Challenges where folks can post their challenge ideas and get (usually more constructive) feedback before going live. I certainly hope you'll stick around and continue to write challenges!
– Alex A. – 2016-04-16T21:36:10.2375
If you have any questions about how the site works, I encourage you to ask on Meta or join us in chat and we'll try to help however we can. Thanks for being a member of the community and again I hope you'll stay.
– Alex A. – 2016-04-16T21:38:43.720