mirror of
https://github.com/vee1e/Write-ups.git
synced 2026-09-01 19:17:10 +00:00
Delete Cbc.py
This commit is contained in:
parent
37c401e8e0
commit
a276f348ca
1 changed files with 0 additions and 34 deletions
|
|
@ -1,34 +0,0 @@
|
|||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import pad, unpad
|
||||
from os import urandom
|
||||
|
||||
def cbc_encrypt(msg: bytes):
|
||||
msg = pad(msg, 16)
|
||||
msg = [msg[i:i+16] for i in range(0, len(msg), 16)]
|
||||
key = urandom(16)
|
||||
out = []
|
||||
for block in msg:
|
||||
cipher = AES.new(key, AES.MODE_ECB)
|
||||
next = cipher.encrypt(block)
|
||||
out.append(next)
|
||||
key = next
|
||||
out = b"".join(out)
|
||||
return key, out
|
||||
|
||||
ct = b"\xa2\xb8 <\xf2\x85\xa3-\xd1\x1aM}\xa9\xfd4\xfag<p\x0e\xb7|\xeb\x05\xcbc\xc3\x1e\xc3\xefT\x80\xd3\xa4 ~$\xceXb\x9a\x04\xf0\xc6\xb6\xd6\x1c\x95\xd1(O\xcfx\xf2z_\xc3\x87\xa6\xe9\x00\x1d\x9f\xa7\x0bm\xca\xea\x1e\x95T[Q\x80\x07we\x96)t\xdd\xa9A 7dZ\x9d\xfc\xdbA\x14\xda9\xf3\xeag\xe3\x1a\xc8\xad\x1cnL\x91\xf6\x83'\xaa\xaf\xf3i\xc0t=\xcd\x02K\x81\xb6\xfa.@\xde\xf5\xaf\xa3\xf1\xe3\xb4?\xf9,\xb2:i\x13x\xea1\xa0\xc1\xb9\x84"
|
||||
ciphertext = ct[2*len(ct)//3-16:]
|
||||
key = ct[2*len(ct)//3 - 32:2*len(ct)//3-16]
|
||||
|
||||
def cbc_decrypt(ciphertext,key):
|
||||
ct = [ciphertext[i:i+16] for i in range(0, len(ciphertext), 16)]
|
||||
out = []
|
||||
for block in ct:
|
||||
cipher = AES.new(key, AES.MODE_ECB)
|
||||
next = cipher.decrypt(block)
|
||||
out.append(next)
|
||||
key = block
|
||||
out = b"".join(out)
|
||||
return out
|
||||
|
||||
plaintext = cbc_decrypt(ciphertext,key).decode()
|
||||
print(plaintext)
|
||||
Loading…
Add table
Add a link
Reference in a new issue