# [GKCTF 2021]RRRRsa

42 篇文章 13 订阅

## [GKCTF 2021]RRRRsa

{ h i n t 1 = ( 2020 ∗ p 1 + q 1 ) 202020 ( m o d   n 1 ) h i n t 2 = ( 2021 ∗ p 1 + 212121 ) q 1 ( m o d   n 1 ) h i n t 3 = ( 2020 ∗ p 2 + 2021 ∗ q 2 ) 202020 ( m o d   n 2 ) h i n t 4 = ( 2021 ∗ p 2 + 2020 ∗ q 2 ) 212121 ( m o d   n 2 ) \begin{cases} hint1 = (2020*p1+q1)^{202020} (mod\ n1) \\ hint2 = (2021*p1+212121)^{q1} (mod\ n1) \\ hint3 = (2020*p2+2021*q2)^{202020}(mod\ n2) \\ hint4 = (2021*p2+2020*q2)^{212121}(mod\ n2)\end{cases}

p 为 素 数 ， 则 对 任 意 a 有 a p = a   ( m o d   p ) p为素数，则对任意a有\\ a^p = a\ (mod\ p)

{ h i n t 1 = ( 2020 ∗ p 1 ) 202020 + q 1 202020 ( m o d   n 1 ) h i n t 2 = 2021 ∗ p 1 + 212121 ( m o d   q 1 ) \begin{cases} hint1 = (2020*p1)^{202020} + q1^{202020}\quad (mod\ n1) \\ hint2 = 2021*p1+212121\quad(mod\ q1) \end{cases}

{ h i n t 3 = ( 2020 ∗ p 2 ) 202020 + ( 2021 ∗ q 2 ) 202020 ( m o d   n 2 ) h i n t 4 = ( 2021 ∗ p 2 ) 212121 + ( 2020 ∗ q 2 ) 212121 ( m o d   n 2 ) \begin{cases} hint3 = (2020*p2)^{202020}+(2021*q2)^{202020}\quad (mod\ n2) \\hint4 = (2021*p2)^{212121}+(2020*q2)^{212121}\quad(mod\ n2)\end{cases}

{ h i n t 1 = ( 2020 ∗ p 1 ) 202020 + k 1 ∗ q 1 h i n t 2 − 212121 = 2021 ∗ p 1 + k 2 ∗ q 1 \begin{cases} hint1=(2020*p1)^{202020}+k1*q1 \\ hint2-212121=2021*p1 + k2*q1\end{cases}

= = > { h i n t 1 = ( 2020 ∗ p 1 ) 202020 + k 1 ∗ q 1 ( m o d   n 1 ) ( h i n t 2 − 212121 ) 202020 = ( 2021 ∗ p 1 ) 202020 + ( k 2 ∗ q 1 ) 202020 ( m o d   n 1 ) ==>\begin{cases} hint1=(2020*p1)^{202020}+k1*q1\quad(mod\ n1) \\ (hint2-212121)^{202020} =(2021*p1)^{202020}+(k2*q1)^{202020}\quad (mod\ n1)\end{cases}

= = > { ① 202 1 202020 ∗ h i n t 1 = ( 2020 ∗ 2021 ∗ p 1 ) 202020 + t 1 ∗ q 1 ( m o d   n 1 ) , t 1 = 202 1 202020 ∗ k 1 ② 202 1 202020 ∗ ( h i n t 2 − 212121 ) 202020 = ( 2020 ∗ 2021 ∗ p 1 ) 202020 + t 2 ∗ q 1 ( m o d   n 1 ) , t 2 = ( 2020 ∗ k ) 202020 ∗ q 1 202019 ==>\begin{cases} ①2021^{202020}*hint1 =(2020*2021*p1)^{202020}+t1*q1\quad (mod\ n1),\quad t1=2021^{202020}*k1 \\②2021^{202020}*(hint2-212121)^{202020} =(2020*2021*p1)^{202020}+t2*q1\quad (mod\ n1),t2 = (2020*k)^{202020}*q1^{202019} \end{cases}

② − ① = k ∗ q 1 ( m o d   n 1 ) 即 ② − ① = k ∗ q 1 + t ∗ n 1 = k 3 ∗ q 1 , ( k = t 2 − t 3 , t , k 3 ∈ Z ) 所 以 q 1 = g c d ( ② − ① , n 1 ) \quad②-① = k*q1 \quad(mod\ n1) \\ 即②-① = k*q1+t*n1 = k3*q1,\quad (k=t2-t3,t,k3∈Z)\\ 所以q1 = gcd(②-①,n1)

{ 202 1 202020 ∗ h i n t 3 = ( 2021 ∗ 2020 ∗ p 2 ) 202020 + ( 202 1 2 ∗ q 2 ) 202020 ( m o d   n 2 ) 202 0 212121 ∗ h i n t 4 = ( 2021 ∗ 2020 ∗ p 2 ) 212121 + ( 202 0 2 ∗ q 2 ) 212121 ( m o d   n 2 ) \begin{cases} 2021^{202020}*hint3 = (2021*2020*p2)^{202020}+(2021^2*q2)^{202020}\quad (mod\ n2) \\2020^{212121}*hint4 = (2021*2020*p2)^{212121}+(2020^2*q2)^{212121}\quad(mod\ n2)\end{cases}

{ ① ( 202 1 202020 ∗ h i n t 3 ) 212121 = ( 2021 ∗ 2020 ∗ p 2 ) 202020 ∗ 212121 + ( 202 1 2 ∗ q 2 ) 202020 ∗ 212121 ( m o d   n 2 ) ② ( 202 0 212121 ∗ h i n t 4 ) 202020 = ( 2021 ∗ 2020 ∗ p 2 ) 202020 ∗ 212121 + ( 202 0 2 ∗ q 2 ) 2020202 ∗ 212121 ( m o d   n 2 ) \begin{cases} ①(2021^{202020}*hint3)^{212121} = (2021*2020*p2)^{202020*212121}+(2021^2*q2)^{202020*212121}\quad (mod\ n2) \\②(2020^{212121}*hint4)^{202020} = (2021*2020*p2)^{202020*212121}+(2020^2*q2)^{2020202*212121}\quad(mod\ n2)\end{cases}

② − ① = k 1 ∗ q 2 ( m o d   n 2 ) 即 ② − ① = k 1 ∗ q 2 + k 2 ∗ n 2 = k ∗ q 2 从 而 q 2 = g c d ( ② − ① , n 2 ) \quad②-① = k1*q2\quad(mod\ n2)\\ 即②-① = k1*q2+k2*n2=k*q2\\ 从而q2=gcd(②-①,n2)

import gmpy2
c=13492392717469817866883431475453770951837476241371989714683737558395769731416522300851917887957945766132864151382877462142018129852703437240533684604508379950293643294877725773675505912622208813435625177696614781601216465807569201380151669942605208425645258372134465547452376467465833013387018542999562042758
n1=75003557379080252219517825998990183226659117019770735080523409561757225883651040882547519748107588719498261922816865626714101556207649929655822889945870341168644508079317582220034374613066751916750036253423990673764234066999306874078424803774652754587494762629397701664706287999727238636073466137405374927829
c1=68111901092027813007099627893896838517426971082877204047110404787823279211508183783468891474661365139933325981191524511345219830693064573462115529345012970089065201176142417462299650761299758078141504126185921304526414911455395289228444974516503526507906721378965227166653195076209418852399008741560796631569
hint1=23552090716381769484990784116875558895715552896983313406764042416318710076256166472426553520240265023978449945974218435787929202289208329156594838420190890104226497263852461928474756025539394996288951828172126419569993301524866753797584032740426259804002564701319538183190684075289055345581960776903740881951
hint2=52723229698530767897979433914470831153268827008372307239630387100752226850798023362444499211944996778363894528759290565718266340188582253307004810850030833752132728256929572703630431232622151200855160886614350000115704689605102500273815157636476901150408355565958834764444192860513855376978491299658773170270
n2=114535923043375970380117920548097404729043079895540320742847840364455024050473125998926311644172960176471193602850427607899191810616953021324742137492746159921284982146320175356395325890407704697018412456350862990849606200323084717352630282539156670636025924425865741196506478163922312894384285889848355244489
c2=67054203666901691181215262587447180910225473339143260100831118313521471029889304176235434129632237116993910316978096018724911531011857469325115308802162172965564951703583450817489247675458024801774590728726471567407812572210421642171456850352167810755440990035255967091145950569246426544351461548548423025004
hint3=25590923416756813543880554963887576960707333607377889401033718419301278802157204881039116350321872162118977797069089653428121479486603744700519830597186045931412652681572060953439655868476311798368015878628002547540835719870081007505735499581449077950263721606955524302365518362434928190394924399683131242077
hint4=104100726926923869566862741238876132366916970864374562947844669556403268955625670105641264367038885706425427864941392601593437305258297198111819227915453081797889565662276003122901139755153002219126366611021736066016741562232998047253335141676203376521742965365133597943669838076210444485458296240951668402513
e = 65537

#求p
hint1 = (hint1 * pow(2021,202020,n1))%n1
hint2 = (pow(hint2-212121,202020,n1)*pow(2020,202020,n1))%n1
q1 = gmpy2.gcd(hint2-hint1,n1)
print(q1)
p1 = n1 // q1
d1 = gmpy2.invert(e,(p1-1)*(q1-1))
p = pow(c1,d1,n1)

#求q
hint3 = pow(hint3 * pow(2021,202020,n2),212121,n2)
hint4 = pow(hint4 * pow(2020,212121,n2),202020,n2)
q2 = gmpy2.gcd(hint4-hint3,n2)
print(q2)
p2 = n2 // q2
d2 = gmpy2.invert(e,(p2-1)*(q2-1))
q = pow(c2,d2,n2)

n = p * q
d = gmpy2.invert(e,(p-1)*(q-1))
m = pow(c,d,n)
print(long_to_bytes(m))



• 2
点赞
• 4
收藏
觉得还不错? 一键收藏
• 5
评论
07-20
04-15 1016
03-13 386
06-03 290

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