boxmoe_header_banner_img

⋅無⋅限⋅進⋅步⋅

加载中

文章导读

BUUCTF-Crypto:rsarsa


avatar
yuhui 2025年11月7日 14

rsarsa

题目:

Math is cool! Use the RSA algorithm to decode the secret message, c, p, q, and e are parameters for the RSA algorithm. Use RSA to find the secret message
数学很酷!使用RSA算法解码这份密信,c、p、q、e都是RSA算法的参数,使用RSA找到密钥!

p = 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e = 65537
c = 83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034

(N,d)是私钥,(N,e)是公钥,公钥加密,私钥解密,c是密文,求明文

p , q 是任选大素数

n=pq φ(n) =(p-1)(q-1)

e*d=1modφ(n) (e*d)modφ(n)=1

加密:Sig(x)=x^e mod n

解密:x=Sig(x)^d mod n

第一步:求n,n=p*q

N=114573516752272714750064227635008832737477859608443481000717283425702025029279291376859256856603741797722497252841363753834114679306784379319341824813349417007577541466886971550474580368413974382926969910999462429631003527365143148445405716553105750338796691010126879918594076915709977585368841428779903869581

第二步:求φ(n):φ(n) = (p – 1) * (q – 1)

φ=114573516752272714750064227635008832737477859608443481000717283425702025029279291376859256856603741797722497252841363753834114679306784379319341824813349395484310674476074262867516991704330586676279176131878754135601460783229276940745427904455048854467754090254652258775177617277116136508905378817444751921692

第三步:求私钥指数(d):(e*d)modφ(n)=1

d=56632047571190660567520341028861194862411428416862507034762587229995138605649836960220619903456392752115943299335385163216233744624623848874235303309636393446736347238627793022725260986466957974753004129210680401432377444984195145009801967391196615524488853620232925992387563270746297909112117451398527453977

第四步:解密消息(M):M = c^d mod n

m=5577446633554466577768879988

# RSA解密
p = 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e = 65537
c = 83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034

# 计算 模数n 和 欧拉函数ϕ(n)
n = p * q
ϕn = (p - 1) * (q - 1)

# 计算私钥d,满足(d*e) mod ϕ(n)=1
d = pow(e, -1, ϕn)

# 解密得到明文m ,满足m=c^d mod n
m = pow(c, d, n)

# 转换为字符串并生成Flag
secret_message = str(m)
flag = f"flag{{{secret_message}}}"

print("解密后的Flag为:", flag)

flag{5577446633554466577768879988}



评论(0)

查看评论列表

暂无评论


发表评论

表情 颜文字

插入代码