首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python加密: DES CTR解密

python加密: DES CTR解密
EN

Stack Overflow用户
提问于 2012-11-23 19:43:37
回答 1查看 1.2K关注 0票数 1

我在这里找到了由here提供的以下代码:atomicinf's code!代码是:

代码语言:javascript
复制
import Crypto.Cipher.AES
import Crypto.Util.Counter

key = "0123456789ABCDEF" # replace this with a sensible value, preferably the output of a hash
iv = "0000000000009001" # replace this with a RANDOMLY GENERATED VALUE, and send this with the ciphertext!

plaintext = "Attack at dawn" # replace with your actual plaintext

ctr = Crypto.Util.Counter.new(128, initial_value=long(iv.encode("hex"), 16))

cipher = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CTR, counter=ctr)
print cipher.encrypt(plaintext)

我的问题是:解密是如何工作的?(显然,我必须手动导入计数器或将当前计数器保存在某个地方)。第二,DES呢?我知道它有更小的计数器,但是我怎么定义它呢?

EN

回答 1

Stack Overflow用户

发布于 2012-12-13 05:28:52

CTR模式的解密与加密的工作方式相同,也就是说,要解密,您应该第二次调用'encrypt‘。这是因为在CTR模式中,对于每个下一块,IV都会递增,并使用AES算法进行加密,并将结果与明文进行异或运算。再次对其进行异或运算将返回cleartext。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13528444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档