Pesho loves to chat with Penka but his parents really like to follow his conversations. One day Pesho invented a revolutionary way to encrypt his messages:
-
First, he generates a decryption key which is a random permutation of all Latin letters (both small and capital)
This permutation presents each letter transformation where the index of the letter is the number of the original letter in the alphabet and the value (the letter in permutation) is its transformation
The indexes are:- a-z => 0-25
- A-Z => 26-51
-
After that, he transforms each letter of his original message according to the key.
-
After that, Pesho converts each letter of the encrypted message to an integer index as follow: The indexes are:
-
A-Z => 0-25
-
a-z => 26-51
-
Finally, he concatenates the key and the encrypted message
The decryption algorithm, which he uses to read what Penka sent him is the same algorithm, but in reverse.
Your task is to decrypt Penka's message, and after that, encrypt Pesho's message.
- The first line of the standard input is encrypted message from Penka.
- The second line contains Pesho's key and his original message
- The first line of standard output must be the decrypted message from Penka
- The second line must be the encrypted message from Pesho
- Pesho's original message can't contain symbols different than letters and you must ignore them (including spaces - ' ')
Input | Output |
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ abcd.e.f.g,h#i4j5klmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ26272829303132333435363738394041424344454647484950510001020304050607080910111213141516171819202122232425 |
eUghSptuVmwOkPMQAZXRjHoJFzDsKxIdBvyLTrcfEiYnWqlbGNaC312624423109 EcdPMfrnoxKDeyCvAXzajmVTQhIsFNlHJYupbSWkZUGqwBOgRtLi H4.e,O_/Nc | NYQTNx EcdPMfrnoxKDeyCvAXzajmVTQhIsFNlHJYupbSWkZUGqwBOgRtLi2412253629 |