문제코드
from Crypto.Cipher import AES
import random
def padding(plaintext):
block_size = 32
if len(plaintext) % block_size != 0:
plaintext += b'\x00' * (block_size - (len(plaintext) % block_size))
return plaintext
def make_key():
key = b''
for i in range(16):
key += str(random.randrange(0, 2)).encode('utf-8')
return key
FLAG = b'~~~~~~~~~~~~~~~'
FLAG = padding(FLAG)
key = make_key()
cipher = AES.new(key, AES.MODE_ECB)
ciphertext = cipher.encrypt(FLAG)
print(ciphertext)
decryption_code
from Crypto.Cipher import AES
def find_key(i):
key =b''
key += str(format(i,'b')).encode('utf-8').zfill(16)
return key
ciphertext=b'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
for i in range(65536):
key = find_key(i)
print(key)
cipher = AES.new(key, AES.MODE_ECB)
plaintext = cipher.decrypt(ciphertext)
if b'DSU' in plaintext:
print("Find plain text: "+plaintext.decode('utf-8'))
break
'교내해킹대회 > Crypto' 카테고리의 다른 글
Binary (0) | 2020.05.17 |
---|---|
What is your major (0) | 2020.05.14 |