[b01lers2020]safety_in_numbers1

一个公钥文件和一个flag文件,进行公钥解析后发现n特别大而e是65537。所以大概就是一道小明文爆破。会运行10分钟作业好像才能有结果

import Crypto.PublicKey.RSA as RSA
from Crypto.Util.number import *
with open(r"C:\Users\mqy23\Downloads\attachment\safety_in_numbers\pubkey.pem",'r')as f:
    key=RSA.importKey(f.read())
e=key.e
#print(e)

with open(r"C:\Users\mqy23\Downloads\attachment\safety_in_numbers\flag.enc",'rb')as s:
    flag=s.read()
c=int.from_bytes(flag,byteorder='little')
import gmpy2
print(long_to_bytes(gmpy2.iroot(c,e)[0]))
import sys
import Crypto.PublicKey.RSA as RSA


def enc(msg, pubkey):
   (n,e) = pubkey
   m = int.from_bytes(msg, byteorder = 'little')
   c = pow(m, e, n)
   ctxt = (c).to_bytes(c.bit_length() // 8 + 1, byteorder = 'little')
   return ctxt


with open("pubkey.pem", "r") as f:
   ciph = RSA.importKey(f.read())     # chill out, Crypto.RSA takes its sweet time... (minutes)

pubkey = (ciph.n, ciph.e)


with open("flag.txt", "rb") as f:
   flag = f.read()

sys.stdout.buffer.write(enc(flag, pubkey))

这里题目文件里写了m = int.from_bytes(msg, byteorder = 'little')

byteorder部分可以写little(逆序输出)或者big(正序)

最后得到flag的倒叙,转换一下即可。

c='}f00Rp_3RutUf!{ftcp'
print(c[::-1])
#pctf{!fUtuR3_pR00f}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值