亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

給定明文、密文和 IV。我可以找到重復使用的鑰匙嗎?

給定明文、密文和 IV。我可以找到重復使用的鑰匙嗎?

烙印99 2023-08-22 14:53:05
大家好我被一門編程課的作業的一部分所困擾。我相信解決方案非常簡單,但出于某種原因我無法理解它。作業的目標是修改密文,使美元金額嚴格增加。加密和解密的類是給定的,不能編輯,添加代碼進行攻擊。攻擊充當中間人,并在調用解密之前檢索加密的輸出。請注意,密鑰是從重復使用的文件中檢索的,因此每次加密和解密都使用相同的密鑰。我們還可以假設我們知道消息的布局。我最初的反應是,因為我們知道密鑰是相同的,并且因為我們有明文、密文和攻擊中的 IV,所以必須有一個簡單的解決方案來修改密文。我嘗試在修改密文后計算一個新標簽,但密文依賴于先前的輸入(IV),因此這不起作用。我假設有一個相對簡單的解決方案是否正確?注意:不一定要尋找完整編碼的答案,只是需要一些解決此問題的方法的指導。助教的辦公時間很混亂,網上的一切都亂七八糟:(謝謝!#### EXAMPLE KEY #####2D7F8E92A8E7109258C879F878E12387######################class encryptimport sysimport osimport Crypto.Cipher.AESimport hashlibf = open(sys.argv[1], 'r')key = f.readline()key = bytes.fromhex(key[:32])f.close()message = \"""AMOUNT: $  10.00Originating Acc Holder: DoeOrgininating Acc #82123-098370I authorized the above amount to be transferred to the account #38108-443280held by a student at the National Bank of the Cayman Islands."""iv = os.urandom(16)cipher = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CBC, IV=iv)ciphertext = cipher.encrypt(message.encode()).hex()tag = hashlib.sha256(message.encode()).hexdigest()print(iv.hex() + ciphertext + tag)class decryptimport sysimport Crypto.Cipher.AESimport hashlibf = open(sys.argv[1], 'r')key = f.readline()key = bytes.fromhex(key[:32])f.close()ciphertextWithTag = bytes.fromhex(sys.argv[2]) # bytes.fromhex($CT)if len(ciphertextWithTag) < 16+16+32:  print("Ciphertext is too short!")  sys.exit(0)iv = ciphertextWithTag[:16]ciphertext = ciphertextWithTag[:len(ciphertextWithTag)-32]  # with ivtag = ciphertextWithTag[len(ciphertextWithTag)-32:]cipher = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CBC, IV=iv)plaintext = cipher.decrypt(ciphertext[16:]) # here [16:] has spare apart ivif tag.hex() != hashlib.sha256(plaintext).hexdigest():   print("Invalid tag!")else:   print("Verified message")   print(plaintext.decode())class attack
查看完整描述

1 回答

?
互換的青春

TA貢獻1797條經驗 獲得超6個贊

查看使用 CBC 模式解密的第一個塊

   PlainText = Decrypt(CipherText, Key) ^ IV.

您知道 PlainText,也知道 IV,并且您有一個想要創建的新文本 FakeText。應該非常清楚如何將 IV 更改為新的 IV',以便最終得到 FakeText 而不是 PlainText。你并不關心解密的結果是什么,只關心它是某個常數。

除此之外,這是你的作業。


查看完整回答
反對 回復 2023-08-22
  • 1 回答
  • 0 關注
  • 1597 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號