BUUCTF_N1book_[第七章 CTF之CRYPTO章]BabyRSA
题目:
from Crypto.Util.number import *
flag = bytes_to_long("n1book{*********}")
p = getPrime(128)
q = getPrime(128)
n = p * q
e = 65537
cipher = pow(flag, e, n)
print n, cipher
# 69343391982073836527260787066436662760820725339907775857387709078502658633087
# 19914364722342610626569065936888842248099105322649309104924491672406432347316
已知n,用yafu分解n,得到q,p:
q=306646691207889915109374013611076713401
p=226134486267985710544345427491176087287
那么已知p,q,n,e,就可以脚本解m(flag)
#!/usr/bin/env python # -*- coding:utf-8 -*- import binascii import gmpy2 import Crypto.Util p=226134486267985710544345427491176087287 q=306646691207889915109374013611076713401 e=65537 c=19914364722342610626569065936888842248099105322649309104924491672406432347316 n=q*p phi=(p-1)*(q-1) d=gmpy2.invert(e,phi) m=pow(c,d,n) print(hex(m)) print(binascii.unhexlify(hex(m)[2:].strip("L")))
flag:
flag{ju5t_f4ctor1z3_N}