-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge18.py
More file actions
33 lines (26 loc) · 817 Bytes
/
Copy pathchallenge18.py
File metadata and controls
33 lines (26 loc) · 817 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
27
28
29
30
31
32
import challenge5
import challenge6
import challenge7
import challenge11
import base64
import struct
def aes_ctr_encrypt(s, key, nonce=0):
if type(s) == str:
s = s.encode('utf-8')
if type(key) == str:
key = key.encode('utf-8')
blocks = challenge6.get_blocks(s)
nonce = struct.pack('<Q', nonce)
out = b''
for i, block in enumerate(blocks):
block_id = struct.pack('<Q', i)
ct = nonce + block_id
keystream = challenge7.aes_encrypt_single_block(key, ct)
out += challenge5.xor(block, keystream)
return out
if __name__ == '__main__':
key = b'YELLOW SUBMARINE'
nonce = 0
ct = base64.b64decode(b'L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ==')
pt = aes_ctr_encrypt(ct, key, nonce)
print(pt)