Find your way to discover an "a1", the inverse of the key(a1: a^(-1)), without using the brute-force loop like the example code
Then return the secret text
Note: a x a1 = 1 (modulo 26)
Example: 7 x -11 = 1 (modulo 26) >> a1 = -11
In order to find the secret text:
secret_text = ""
for c in ciphertext:
e = (a1 * (char2num(c) - b)) % m
secret_text = secret_text + num2char(e)
def char2num(c):
return ord(c) - 65
def num2char(n):
return chr(n + 65)
def a_little_decryption(a, b, m, ciphertext):
secret_text = ""
a1 = None
for i in range(0, m):
if (a*i)%m == 1:
a1 = i
break
for c in ciphertext:
e = (a1 * (char2num(c) - b)) % m
secret_text = secret_text + num2char(e)
return secret_text
test.assert_equals(a_little_decryption(7, 5, 26, "VZZAQZM"), "GOODJOB")
test.assert_equals(a_little_decryption(17, 2 , 26, "HCPBIPA"), "LANDING")
test.assert_equals(a_little_decryption(359, 499 , 26, "TWNYOHLP"), "SHORTKEY")