# Arup Guha
# 7/3/2012
# Utility to help break affine cipher

def main():

    cipher = input("Enter the cipher text, all uppercase.\n")

    # Go through all a's
    for a in range(1,26):

        # Screen out invalid values.
        if gcd(a, 26) != 1:
            continue

        # Go through all b's
        for b in range(26):

            # Row header
            print(a,b,' ',end="")

            # Convert each character and print.
            for i in range(len(cipher)):

                out = (a*(ord(cipher[i])-ord('A')) + b)%26
                print((chr)(out + ord('A')), end="")

            print()

# Finds the gcd of a and b.
def gcd(a, b):

    if a == 0:
        return b
    if b == 0:
        return a
    return gcd(b, a%b)

main()
