7.19刷题

[b01lers2020]safety_in_number

flag.enc
pubkey.pem
和一个加密py
pubkey告诉我们n很大
e=65537
读取c
因为n很大
c直接开e次方
因为是“little”
所以需要逆序

import gmpy2
from Crypto.Util.number import *
e=65537
with open('flag.enc','rb') as f:
    cipher = f.read()
c = int.from_bytes(cipher, byteorder='little')
m=gmpy2.iroot(c,e)[0]
print(long_to_bytes(m)[::-1])

[AFCTF2018]MyOwnCBC

有py可知每一个密文都作为密钥加密
初始的key就是密文的前32位

from Crypto.Cipher import AES
with open("flag_cipher","rb") as f:
    a=f.read()
    f.close
key0=a[:32]
def decode(key,c):
     c=[c[i:i+32] for i in range(0,len(c),32)]
     tempkey=key0
     plain = b''
     for i in range(1,len(c)):
        aes=AES.new(tempkey,AES.MODE_ECB)
        plain+=aes.decrypt(c[i])
        tempkey=c[i]
     return plain
print(decode(key0,a))

你可能感兴趣的:(刷题记录)