好了,所以這裏是到目前爲止我的代碼:而在Python使用lambda屬性錯誤
import os
import time
import random
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random
from Crypto.Cipher import AES
import base64
key = 'MIICWwIBAAKBgQDN'
print('do you have a encrypted string in a file?')
fileexist = input('if so then input 1:')
if fileexist == 1:
filename = raw_input('please input path to file:')
file = open(filename,'r')
encoded = file.read()
type = type(encoded)
else:
encoded = raw_input('please enter encrypted text')
encoded = str(encoded)
BLOCK_SIZE = 16
PADDING = '{'
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
decoded = DecodeAES(key, encoded)
print(decoded)
我一直線歌廳一個屬性錯誤24我確切的錯誤信息是波紋管
AttributeError: 'str' object has no attribute 'decrpt'
我我試圖用AES解密一條消息。使用幾乎完全相同的語法,我的加密器工作得很好。我沒有完全理解錯誤的原因。我知道這是可能的,我已經看到其他職位使用這種語法。設置
看起來你的代碼中有一個錯字,或者錯誤信息是你正在嘗試'刪除'你的字符串。檢查你的拼寫? – bcc32
我要離開這段代碼:http://www.codekoala.com/posts/aes-encryption-python-using-pycrypto/本身它可以正常編輯,但是當我將lambda行粘貼到我的代碼中時它錯誤了。我不知道什麼? – MathMXC
鍵只是您的代碼中的一個字符串,它沒有解密方法。你是否打算設置'key = AES.new('MIICWwIBAAKBgQDN')'而不是? – bcc32