Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python字符串加密/解密错误_Python_Encryption - Fatal编程技术网

python字符串加密/解密错误

python字符串加密/解密错误,python,encryption,Python,Encryption,我一直在关注这个链接,我认为这是一个错误。这是我解密加密字符串时得到的输出。我无法复制它,因此这是图像: 它应该解密到mYs3cr3t字符串 编辑,这是我的代码: def encrypt(self,param): BLOCK_SIZE = 16 PADDING = '{' pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING EncodeAES =

我一直在关注这个链接,我认为这是一个错误。这是我解密加密字符串时得到的输出。我无法复制它,因此这是图像:

它应该解密到
mYs3cr3t字符串

编辑,这是我的代码:

def encrypt(self,param):
        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 = "mynotsosecretkey"
        print 'encryption key:',secret
        cipher = AES.new(secret)

        encoded = EncodeAES(cipher, param)
        print 'Encrypted string:', encoded

        return (encoded,secret)

    def decryption(self,passwd):
        PADDING = '{'
        DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)

        encryption,key = self.encrypt(passwd)

        cipher = AES.new(key)
        decoded = DecodeAES(cipher, encryption)
        print decoded

至于输出,我无法复制它,因为它包含一些奇怪的字符。

请在此处发布相关代码。如果你在解释器中运行这个例子(例如空闲),你也可以复制输出。你看到的应该是明文。请打印数据的python表示形式,而不是字符串本身,方法是写入
print“Decrypted,不加填充:”+repr(decoded)
。另外,请为所有中间值添加这样一行:
encrypt
print“param:”+repr(param)
print“padded param:”+repr(pad(param))
;在
解密中
打印“密文”:+repr(cipher.decrypt(passwd))