RSA共模攻击

题目:

n1= 20367004933619640329031799226776514837061685981664854285308115632909435670724596920128402172098160576548639864098528644817516365660648152982472184401323785790562533467196556834124275893853534815001482876360398354954695792370636033673202145070244264275187457752956505832556854269231285319773348399301741813934834487846223229051935634443669493220012667872355681808618502449585839172939977649524262173256707695568263984472286856069995773192355643301872930251256460438128472182620887659172465881490174220827917135702261368000920219514539361766564775919476617752618166100973206718108473026971567131239107358379641923763013
n2= 20367004933619640329031799226776514837061685981664854285308115632909435670724596920128402172098160576548639864098528644817516365660648152982472184401323785790562533467196556834124275893853534815001482876360398354954695792370636033673202145070244264275187457752956505832556854269231285319773348399301741813934834487846223229051935634443669493220012667872355681808618502449585839172939977649524262173256707695568263984472286856069995773192355643301872930251256460438128472182620887659172465881490174220827917135702261368000920219514539361766564775919476617752618166100973206718108473026971567131239107358379641923763013
e1= 2333
e2= 23333
c1= 10264744066430466481593872630149143558573077174416980857009118692134660819073913212595308263898462327337283768644911383152506209840559778285757586705322364622425329621425100366723498923698716160356383331699930898455469318543849123623408889653265452565954257437198570129871082756267930336123137826093005304199337852991417533302939219968193861864872868938531890911844179764341487167273826185141101537209604030231278035081281820795150900579415774349854010257952836794529900536730723453110219127519437954530016383921843131179651083796172790701851004000889426375776340135273928938349542525459256006377475939436412482003970
c2= 5419945808600875685324905255766599302044490914532517430566320331248051121989090272712976205411073231922350575383585807837699039790705965844972602000549867253273355997765191642673804824094384527196797854210696722264604208353972695860473231983654542614752370002709975410103077627528638449599044074982480645065659196532121501525242050349677315892712735554820817806905097442560421171589689581990204756724213720035752010249253635380639611831099379821172339940499162281183608981563319912252895890992937277744761454652788338855099270346501953960046919430422924656133558212488023532963289949329182442150206387260469485512737
import gmpy2
from Crypto.Util.number import *

# n1 = 20367004933619640329031799226776514837061685981664854285308115632909435670724596920128402172098160576548639864098528644817516365660648152982472184401323785790562533467196556834124275893853534815001482876360398354954695792370636033673202145070244264275187457752956505832556854269231285319773348399301741813934834487846223229051935634443669493220012667872355681808618502449585839172939977649524262173256707695568263984472286856069995773192355643301872930251256460438128472182620887659172465881490174220827917135702261368000920219514539361766564775919476617752618166100973206718108473026971567131239107358379641923763013
n = 20367004933619640329031799226776514837061685981664854285308115632909435670724596920128402172098160576548639864098528644817516365660648152982472184401323785790562533467196556834124275893853534815001482876360398354954695792370636033673202145070244264275187457752956505832556854269231285319773348399301741813934834487846223229051935634443669493220012667872355681808618502449585839172939977649524262173256707695568263984472286856069995773192355643301872930251256460438128472182620887659172465881490174220827917135702261368000920219514539361766564775919476617752618166100973206718108473026971567131239107358379641923763013
e1 = 2333
e2 = 23333
c1 = 10264744066430466481593872630149143558573077174416980857009118692134660819073913212595308263898462327337283768644911383152506209840559778285757586705322364622425329621425100366723498923698716160356383331699930898455469318543849123623408889653265452565954257437198570129871082756267930336123137826093005304199337852991417533302939219968193861864872868938531890911844179764341487167273826185141101537209604030231278035081281820795150900579415774349854010257952836794529900536730723453110219127519437954530016383921843131179651083796172790701851004000889426375776340135273928938349542525459256006377475939436412482003970
c2 = 5419945808600875685324905255766599302044490914532517430566320331248051121989090272712976205411073231922350575383585807837699039790705965844972602000549867253273355997765191642673804824094384527196797854210696722264604208353972695860473231983654542614752370002709975410103077627528638449599044074982480645065659196532121501525242050349677315892712735554820817806905097442560421171589689581990204756724213720035752010249253635380639611831099379821172339940499162281183608981563319912252895890992937277744761454652788338855099270346501953960046919430422924656133558212488023532963289949329182442150206387260469485512737


def gm(e1, e2, c1, c2, n):
    s = gmpy2.gcdext(e1, e2)
    print(s)
    t = s[1]
    print(t)
    z = s[2]
    print(z)
    if t < 0:
        t = -t
        c1 = gmpy2.invert(c1, n)
        print("c1>>>", c1)
    if z < 0:
        t = -t
        c2 = gmpy2.invert(c2, n)
        print("c2>>>", c2)
    m = (pow(c1, t, n) * pow(c2, z, n)) % n
    return m


flag = gm(e1, e2, c1, c2, n)
print(long_to_bytes(flag))
#flag{6480a3bf-82e2-44e0-9c32-b6a0da8ec46d}
posted @ 2025-04-29 22:31  lethe311  阅读(4)  评论(0)    收藏  举报