Ad

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
Code
Diff
  • def rubegoldberg():
        return 2-1
    • def rubegoldberg():
    • return 1
    • return 2-1