【发布时间】:2018-02-10 05:08:46
【问题描述】:
我为一个执行单个字符解密的函数编写了代码。我收到此错误消息:'int' object is not callable,但我不知道这是指哪个对象以及我是如何非法调用某些东西的。我做错了什么?谢谢。
def affine_cipher_decryption(ch,N,alphabet):
M = len(alphabet)
A = get_smallest_co_prime(M)
A_inverse = multiplicative_inverse(A,M)
counter = -1
for element in alphabet:
if element == ch:
counter += 1
index = counter
break
else:
counter += 1
cipher_index = A_inverse(index-N) % M
cipher_ch = alphabet[cipher_index]
return cipher_ch
这是错误回溯消息:
Traceback(最近一次调用最后一次):
文件“”,第 1 行,在 runfile('/Users/brandononeil/Documents/SS18proj04.py', wdir='/Users/brandononeil/Documents')
文件 “/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py”, 第 880 行,在运行文件中 execfile(文件名,命名空间)
文件 “/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py”, 第 102 行,在 execfile 中 exec(编译(f.read(),文件名,'exec'),命名空间)
文件“/Users/brandononeil/Documents/SS18proj04.py”,第 161 行,在 主要()
文件“/Users/brandononeil/Documents/SS18proj04.py”,第 148 行,在 主要的 decr_ch1 = affine_cipher_decryption(ch, rotation, ALPHA_NUM)
文件“/Users/brandononeil/Documents/SS18proj04.py”,第 101 行,在 仿射密码解密 cipher_index = multiplicative_inverse(A,M)(index-N) % M
TypeError: 'int' 对象不可调用
另外,这里是multiplicative_inverse的内容:
def multiplicative_inverse(A,M):
for x in range(M):
if (A*x)%M == 1:
return x
我已经尝试重命名A_inverse,并且我尝试在affine_cipher_decryption 中写入multiplicative_inverse 函数的内容(这样我就不必调用multiplicative_inverse),但无济于事。
还有什么可能出错的想法吗?
【问题讨论】:
-
错误回溯消息指出了错误的确切位置。请编辑您的问题以包含此消息。
-
multiplicative_inverse(A,M)返回什么? -
将
multiplicative_inverse(A,M)(index-N) % M更改为(multiplicative_inverse(A,M)*(index-N)) % M
标签: python