Skip to content

Instantly share code, notes, and snippets.

@Alex-Tsvetanov
Last active September 10, 2017 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alex-Tsvetanov/5502a50d7a5642148b13406d5064b86c to your computer and use it in GitHub Desktop.
Save Alex-Tsvetanov/5502a50d7a5642148b13406d5064b86c to your computer and use it in GitHub Desktop.
Pesho's secret conversation

Pesho's secret conversation

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.

Input

  • The first line of the standard input is encrypted message from Penka.
  • The second line contains Pesho's key and his original message

Output

  • The first line of standard output must be the decrypted message from Penka
  • The second line must be the encrypted message from Pesho

Constrains

  • Pesho's original message can't contain symbols different than letters and you must ignore them (including spaces - ' ')

Examples

InputOutput
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ abcd.e.f.g,h#i4j5klmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ26272829303132333435363738394041424344454647484950510001020304050607080910111213141516171819202122232425
eUghSptuVmwOkPMQAZXRjHoJFzDsKxIdBvyLTrcfEiYnWqlbGNaC312624423109
EcdPMfrnoxKDeyCvAXzajmVTQhIsFNlHJYupbSWkZUGqwBOgRtLi H4.e,O_/Nc
NYQTNx
EcdPMfrnoxKDeyCvAXzajmVTQhIsFNlHJYupbSWkZUGqwBOgRtLi2412253629
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment