# Arup Guha
# 8/21/2024
# Some code to deal with characters and encryption.

# Encrypt the plaintext plain (uppercase) with the affine keys a and b.
def encrypt(plain,a,b):

    ans = ""
    for x in plain:

        # Get numeric value.
        numval = ord(x)
        
        # Scale to be 0 to 25
        numval = numval - ord('A')

        # Get numeric cipher text
        numcipher = (a*numval + b)%26

        # To map back to a character add to ascii value of 'A' then convert
        # to a character.
        ans = ans + chr(numcipher + ord('A'))
    return ans

plain = "KNIGHTS"
print(encrypt(plain, 5, 18))
