我在这里找到了atomicinf的以下代码:atomicinf's code!代码是:
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呢?我知道它有更小的计数器,但我如何定义它呢?在
CTR模式的解密与加密的工作方式相同,即要解密,应第二次调用“encrypt”。 这是因为在CTR模式下,每个下一个块的值都会增加,并用AES算法加密,结果比明文的xored要高。再次使用Xoring返回明文。在
相关问题 更多 >
编程相关推荐