Q:

Python Auto Encryption Program

Hello guys I am a beginner at python and was trying to make an Encryption code which uses an encryption key defined by me for example I made this code but it isn't working:
def encrypt():
    A = "f"
    B = "d"
    C = "z"
    T = "x"
    first = input()
    print(first)

I want the program to function like when a user enters CAT in the input the output should be zax but when I input even A in my current program it prints 
A as it is. 
Any help would be appreciated!

A:

You can just use string.translate method. A sample code would be:
def encrypt():
    encryption_table = {
        ord('A'):ord('f'),
        ord('B'):ord('d'),
        ord('C'):ord('z'),
        ord('T'):ord('x'),                        
    }
    first = input()
    print(first.translate(encryption_table))

For this code an input CAT will return zfx.

