cea*_*sif 7 python cryptography des encryption-symmetric pycrypto
我尝试使用pyDes和Crypto.Cipher.DES模块实现DES算法.我发现了一个问题,当我用82514145密钥加密然后解密密码93505044我可以检索解密的文本.我发现256个键表现得像这样.这违反了密码学.我的代码如下:
from Crypto.Cipher import DES
plain_text = 'asdfghij'
print 'plain Text: ', plain_text
des = DES.new('82514145', DES.MODE_ECB)
cipher_text = des.encrypt(plain_text)
print 'the cipher text is ', cipher_text
des = DES.new('93505044', DES.MODE_ECB)
print 'the decrypted text is: ', des.decrypt(cipher_text)
Run Code Online (Sandbox Code Playgroud)
输出是:
plain Text: asdfghij
the cipher text is @?Z????
the decrypted text is: asdfghij
Run Code Online (Sandbox Code Playgroud)
我的工作有什么不对吗?我也用pyDes得到了相同的结果.
DES密钥只有56位长,但由于奇偶校验位,它们扩展到64位.应设置每个字节的第8位以确保奇校验.
许多加密库忽略了奇偶校验位,这意味着有很多方法可以在64位密钥字符串中表示相同的56位密钥.事实上,有8种不同的方式,这就解释了为什么你找到了256个匹配的密钥.
您的示例包括两个仅在奇偶校验位上不同的键值.见下文 - 奇偶校验位在[]:
82514145
= 0x3832353134313435
= 0011100[0] 0011001[0] 0011010[1] 0011000[1] 0011010[0] 0011000[1] 0011010[0] 0000000[0]
93505044
= 0x3933353035303434
= 0011100[1] 0011001[1] 0011010[1] 0011000[0] 0011010[1] 0011000[0] 0011010[0] 0000000[0]
Run Code Online (Sandbox Code Playgroud)
这两个密钥都不是真正有效的.该密钥的正确表示是:0x3832343134313401.
| 归档时间: |
|
| 查看次数: |
1378 次 |
| 最近记录: |