# Arup Guha
# Substitution Cipher Example

# Applies the subsitution key to plaintext message and returns the ciphertext.
def apply(message, key):

    cipher = ""
    for x in message:
        cipher = cipher + key[ord(x)-ord('A')]
    return cipher

# Returns the corresponding decryption key for the encryption key, key.
def getDecKey(key):

    # Will store my decryption key here as a list at first.
    mykey = ['X']*26

    for i in range(26):
        num = ord(key[i])-ord('A')
        mykey[num] = chr(ord('A')+i)

    dec = ""
    for x in mykey:
        dec = dec + x
    return dec
    
def main():

    # Reads in the input key as an uppercase string of 26 unique letters.
    key = input()

    # Message to encrypt upper case letters only.
    msg = input()

    # Encrypt msg with the key, key for substitution cipher.
    cipher = apply(msg, key)
    print("Encrypted, we have", cipher)

    
    # Get the decryption key
    deckey = getDecKey(key)
    for i in range(len(deckey)):
        print( chr(ord('A')+i), deckey[i])

    plainback = apply(cipher, deckey)
    print("We have recovered the plaintext,", plainback)
    

main()



    
