12
3
Cryptic Kicker
A common but insecure method of encrypting text is to permute the letters of the alphabet. In other words, each letter of the alphabet is consistently replaced in the text by some other letter. To ensure that the encryption is reversible, no two letters are replaced by the same letter. Your task is to decrypt several encoded lines of text, assuming that each line uses a different set of replacements, and that all words in the decrypted text are from a dictionary of known words.
Input
The input consists of lowercase words, in alphabetical order. These words compose the dictionary of words which may appear in the decrypted text. Following the dictionary are several lines of input. Each line is encrypted as described above.
There are no more than 1,000 words in the dictionary. No word exceeds 16 letters. The encrypted lines contain only lower case letters and spaces and do not exceed 80 characters in length.
Output
Decrypt each line and print it to standard output. If there are multiple solutions, any one will do. If there is no solution, replace every letter of the alphabet by an asterisk.
Sample Input
and dick jane puff spot yertle
bjvg xsb hxsn xsb qymm xsb rqat xsb pnetfn
xxxx yyy zzzz www yyyy aaa bbbb ccc dddddd
Sample Output
dick and jane and puff and spot and yertle
**** *** **** *** **** *** **** *** ******
Here's the solution. Please note that I am not a horse running in the race for the shortest bytes / Competitive programmer. I just like puzzles!
(Source)
1Please relax your >input< constraints to something that is applicable for each language. For example a lot of languages will hate, and not appreciate that the format starts with a 6. I'd suggest leaving the format totally unspecified, and only say that the input is a list of words and a list of lines to encrypt. – orlp – 2015-08-08T11:56:04.770
Okay, There you go! – Dhruv Ramani – 2015-08-08T11:56:59.297
1Are there runtime constraints to this? Can I simply iterate through every possible replacement combination, until one works (which would likely take years to finish)? – Nathan Merrill – 2015-08-08T14:27:52.040
@NathanMerrill Do that, and if it's gonna take years, just print it in the star form. Vihan, It's not a duplicate, please read the question properly. – Dhruv Ramani – 2015-08-08T17:33:41.563
Can we just output the words or do we have to join them? – Downgoat – 2015-08-09T00:21:02.617
It's your wish :) – Dhruv Ramani – 2015-08-09T05:08:22.013
Can we have an end constraint of some kind. Some languages have a hard time guessing when you are done with input. For now I am going to operate on the assumption that an empty line denotes the end of input. – LambdaBeta – 2015-08-10T16:02:10.050