[V&N2020 公开赛]easy_RSA

打开分析可以得到

  从题设代码中可以得到的信息有 

    n=p∗q∗r

    d没啥用

    e = 65537

    phi = (q-1)*(p-1)*(r-1)

    c = m2(mod r)

    cipher = ce(mod n)

解题思路

  1.   分解N得到p,q,r
  2.        已知cipher求c
  3.        已知c求m

上才艺

import gmpy2
import binascii
from sympy.ntheory.residue_ntheory import nthroot_mod
from Crypto.Util.number import *
n = 7941371739956577280160664419383740967516918938781306610817149744988379280561359039016508679365806108722198157199058807892703837558280678711420411242914059658055366348123106473335186505617418956630780649894945233345985279471106888635177256011468979083320605103256178446993230320443790240285158260236926519042413378204298514714890725325831769281505530787739922007367026883959544239568886349070557272869042275528961483412544495589811933856131557221673534170105409
cipher = 1618155233923718966393124032999431934705026408748451436388483012584983753140040289666712916510617403356206112730613485227084128314043665913357106301736817062412927135716281544348612150328867226515184078966397180771624148797528036548243343316501503364783092550480439749404301122277056732857399413805293899249313045684662146333448668209567898831091274930053147799756622844119463942087160062353526056879436998061803187343431081504474584816590199768034450005448200
p = 102634610559478918970860957918259981057327949366949344137104804864768237961662136189827166317524151288799657758536256924609797810164397005081733039415393
q = 7534810196420932552168708937019691994681052660068275906973480617604535381306041583841106383688654426129050931519275383386503174076258645141589911492908993
e = 65537
t0 = p*q
r = n//t0
phi = (q-1)*(p-1)*(r-1)
d = gmpy2.invert(q ** 2, p ** 2)
really_d = gmpy2.invert(e,phi)
c = gmpy2.powmod(cipher,really_d,n)
# nthroot_mod(a,n,p) Find the solutions to x**n = a mod p
m = nthroot_mod(c,2,r)
print(m)
print(binascii.unhexlify(hex(m)[2:]))

  得到flag为flag{fd462593-25e4-4631-a96a-0cd5c72b2d1b}

posted @ 2020-12-13 22:41  浩琦很好奇  阅读(363)  评论(0编辑  收藏  举报