# Arup Guha
# 8/28/2025
# Code for CIS 3362 Homework 1, Q3

# Returns the result of encrypting s with Affine keys a,b.
def encrypt(s,a,b):

    # Encrypt
    cipher = ""
    for x in s:
        cipher = cipher + chr ( ord('a') + (a*(ord(x)-ord('a')) + b)%26 )
    return cipher


# Words I will look for.
WORDS = ["the","and","prize"]
POSSIBLEA = [1,3,5,7,9,11,15,17,19,21,23,25]

# This is pretty bad...
cipher= "rozcrrpagodrpivimovxaqsmcvvidrhuviqxadeqboowqbocrbhirmphuzqv"
cipher += "wadrpipozigrpqramqdadmovzovqriaradrosuhimrcviodidaesqrpaguiq"
cipher += "vapqnirvaixqdxtqahixroxorpagadrpiryozqgruiqvgbcraqspozadebuz"
cipher += "crraderpagadyvaradeadqdqggaedsidrayahhtiihroobqxdorroxoar"

# Trying all possible decryption keys.
for a in POSSIBLEA:
    for b in range(26):

        # Try decrypting.
        plain = encrypt(cipher,a,b)

        flag = False

        # If we find one of the words in it, print it!
        for x in WORDS:
            if x in plain:
                print(a,b,plain)

        
