-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathchallenge25.py
More file actions
26 lines (22 loc) · 849 Bytes
/
challenge25.py
File metadata and controls
26 lines (22 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from Cryptodome.Cipher import AES
from Cryptodome.Random import get_random_bytes
from Cryptodome.Random.random import getrandbits
import challenge18
import base64
import struct
key = get_random_bytes(16)
nonce = getrandbits(64)
def ciphertext_oracle():
ecb_ciphertext = base64.b64decode(open('25.txt', 'r').read())
ecb_key = b'YELLOW SUBMARINE'
ecb_cipher = AES.new(ecb_key, AES.MODE_ECB)
plaintext = ecb_cipher.decrypt(ecb_ciphertext)
cipher = challenge18.CTR(AES.new(key, AES.MODE_ECB), nonce)
return cipher.encrypt(plaintext)
def edit(ciphertext, offset, newtext):
cipher = challenge18.CTR(AES.new(key, AES.MODE_ECB), nonce)
cipher.encrypt(b'\x00' * offset)
return ciphertext[0:offset] + cipher.encrypt(newtext)
ciphertext = ciphertext_oracle()
plaintext = edit(ciphertext, 0, ciphertext)
print(plaintext)