我正在尝试用 python 编写一个简单的加密函数。每次我运行它时都会收到一条错误消息,说“未定义加密”,但确实如此。我可以就为什么这个功能不起作用得到一些帮助吗?非常感谢!!!这是代码:
from Crypto.Cipher import AES
import base64
import os
def encryption (privateInfo):
BLOCK_SIZE = 16
PADDING = '{'
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
EncodeAES = lambda c, s: base64.b64encode(c.encrypt (pad(s)))
secret = os.urandom(BLOCK_SIZE)
print 'encryption key: ', secret
cipher = AES.new(secret)
encoded = EncodeAES(cipher, privateInfo)
print 'Encrypted string: ', encoded
我得到的错误信息是:
>>> encryption('secret message that nobody should read')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
encryption('secret message that nobody should read')
NameError: name 'encryption' is not defined