All submissions for this problem are available.
Chef is known to have friends as well as enemies. Chef has a habit of communicating with friends through encrypted messages. But recently some of his enemies found the way to decrypt and get the original message. You need to write a program that simulates how the enemies decrypted the messages.
Chef’s enemies observed that Chef used to first pass N random string before the encrypted message. Afterwards it was noticed that the key to decode the message was hidden in it. The key for decoding was the summation of the values of the key characters.
Key characters are those characters that appear in all the N strings exactly once (exactly once in each of the N strings). A character cannot be considered as key character if it exists in all N String but does not appear exactly once in any of the string.
Once all the key characters are found, the key is the summation of the position of all the key characters in the alphabetical series to mod 26. For example, If the key characters are a,b,c then the key is( 1 + 2 + 3 ) % 26 = 6.If there are no key characters then the default value of the key is 7.
Chef thought finding out this was easy, so he added another twist while encrypting. For all alphabets at index (index starting from 0) which represent a number in Fibonacci Series (0 1 1 2 3 5 and so on), such alphabets were shifted by the key towards right e.g.: a to c, b to d (for key 2). For the rest of alphabets, they were shifted by the key towards left e.g.: d to b, r to p, a to y (for key 2). Also all the numbers or special characters should appear unchanged.
Note: All the Strings are in lowercase
The first line contains a single integer N denoting the N string used for key
Next N lines are the String
Next Line is the encrypted Message which needs to be decoded
A single line containing the DECODED string.
- 1 ≤ N ≤ 100
- 1 ≤ | S | ≤ 100
Input: 4 azfjybgbxnpyatfgcaxqylbxd gzbbbgaxnfatxqdjfaypgcyafl yjbfpcygxlgznyfbgxtqgxydaaa xxyyxxyyxdlbqffctpbngggjz cbkumuwlwkmtt_zwksa!!
Here in the above example, the key characters which exist in all the N strings and appear exactly once in all N strings are 'c', 'd', 'j', 'l', 'n', 'p', ’q’, 't', 'z'
The key is (3 + 4 + 10 + 12 + 14 + 16 + 17 + 20 + 26) % 26 i.e. 122%26 = 18
So, the encryption key is 18
Through this information, we decode the message using opposite steps mentioned in the description.
Original message: kjscecodecell_rocks!!
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions