农民 发表于 2023-11-20 14:16:06

FSCTF 2023(公开赛道)CRYPTO WP

RSA 1

1、题目信息
提交格式:FSCTF{你所解出的内容}p=1458769258361
q=4556983871563
e=17
求d2、解题方法
exp
from gmpy2 import *

p=1458769258361
q=4556983871563
e=17

d = int(invert(e, (p-1)*(q-1)))
print(d)
#FSCTF{5865518808244394324786753}做不出来就别阴阳怪气啦

1、题目信息
啊这?不是吧?就这啊?做不了啊?做不出来就别阴阳怪气啦就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 就 这 ¿ 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 不 会 吧 ? 就 这 ¿ 不 会 吧 ? 2、解题方法
阴阳怪气密码解码
FSCTF{Jiuzhe@JustSoSo}RSA 2

1、题目信息
提交格式:FSCTF{你所解出的内容}c=90362297576572826064831133206230135349790392078780406000643496612200873754835039374184323808342127071833274981191134125413478105835272238356352724573228797863805124195170088819735610736936895478614898105848968069280022022112207095140266709372221090586917729998024205978412679448008696923580889787529663283314
p=8637633767257008567099653486541091171320491509433615447539162437911244175885667806398411790524083553445158113502227745206205327690939504032994699902053229
q=11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e=655372、解题方法
import gmpy2from Crypto.Util.number import long_to_bytesc=90362297576572826064831133206230135349790392078780406000643496612200873754835039374184323808342127071833274981191134125413478105835272238356352724573228797863805124195170088819735610736936895478614898105848968069280022022112207095140266709372221090586917729998024205978412679448008696923580889787529663283314
p=8637633767257008567099653486541091171320491509433615447539162437911244175885667806398411790524083553445158113502227745206205327690939504032994699902053229
q=11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e=65537phi = (p-1) * (q-1)n = p * qd = gmpy2.invert(e, phi)m = pow(c, d, n)print(m)#FSCTF{20230824} RSA 3

1、题目信息
提交格式:FSCTF{你所解出的内容}from Crypto.Util.number import bytes_to_long
m=bytes_to_long(flag)
n= 12308543373374311860115195114269947739026255098864232126071500623399852788903738569949462616714391748269539072128882946132686996592089735285396762634029371785959865779256901123369306119124563405765293657606975290441243965513640680841871955014230301486214824204887945375140818283280272607903500556306646445508386218951500563603482945071727344737690804338144982687000734071274618240408238519378280819162796749148066754028700125846348589164721591354555019608871411236973606149388257533629388508942271702742078883636357856776193846813894734271905070538713351614750057245897158615891962167410053552739441195871000310777649
e= 65537
dp= 28196759050232165736649945458463681080421101473761579424309687746007021074159564720195299959516638110870101025657932732247788828322476803386736345945717104030991724584628153257976163663460034720811420324255626233108130037584679035250792445830510130682783638394418531763109219293027733347554816808577799709553
c= 18557982570442382803270424558327858897631412348831804041585550714430886301130340330504092595136323437426655440434378309597508734319289809102363980266709451843289506925681138198216996964184381573362637998084046987954332439685362567803969109146929494845569504917225276617062550098634819055903717250895873770650003541093960623604400214476074016870822477754533691174248489273868574250510979319837039662536529211139203870080480243087936866439444045419411829979638735799886809655585818852731857215766680014628171502459556282932585120243235155810632352486272231791175495405416421858154899780893670611029201143958713290232082、解题方法
dp泄露
exp
import gmpy2 as gp
e = 65537
n = gp.mpz(12308543373374311860115195114269947739026255098864232126071500623399852788903738569949462616714391748269539072128882946132686996592089735285396762634029371785959865779256901123369306119124563405765293657606975290441243965513640680841871955014230301486214824204887945375140818283280272607903500556306646445508386218951500563603482945071727344737690804338144982687000734071274618240408238519378280819162796749148066754028700125846348589164721591354555019608871411236973606149388257533629388508942271702742078883636357856776193846813894734271905070538713351614750057245897158615891962167410053552739441195871000310777649)
dp = gp.mpz(28196759050232165736649945458463681080421101473761579424309687746007021074159564720195299959516638110870101025657932732247788828322476803386736345945717104030991724584628153257976163663460034720811420324255626233108130037584679035250792445830510130682783638394418531763109219293027733347554816808577799709553)
c = gp.mpz(1855798257044238280327042455832785889763141234883180404158555071443088630113034033050409259513632343742665544043437830959750873431928980910236398026670945184328950692568113819821699696418438157336263799808404698795433243968536256780396910914692949484556950491722527661706255009863481905590371725089587377065000354109396062360440021447607401687082247775453369117424848927386857425051097931983703966253652921113920387008048024308793686643944404541941182997963873579988680965558581885273185721576668001462817150245955628293258512024323515581063235248627223179117549540541642185815489978089367061102920114395871329023208
)
for x in range(1, e):
    if(e*dp%x==1):
      p=(e*dp-1)//x+1
      if(n%p!=0):
            continue
      q=n//p
      phin=(p-1)*(q-1)
      d=gp.invert(e, phin)
      m=gp.powmod(c, d, n)
      if(len(hex(m))%2==1):
            continue
      print('--------------')
      print(m)
      print(hex(m))
      print(bytes.fromhex(hex(m)))
#FSCTF{Cheese_snow_1eop@rd}Big_e

1、题目信息
这么大的e吗?n = 12238605063252292170613110607692779326628090745751955692266649177882959231822580682548279800443278979485092243645806337103841086023159482786712759291169541633901936290854044069486201989034158882661270017305064348254800318759062921744741432214818915527537124001063995865927527037625277330117588414586505635959411443039463168463608235165929831344586283875119363703480280602514451713723663297066810128769907278246434745483846869482536367912810637275405943566734099622063142293421936734750356828712268385319217225803602442033960930413469179550331907541244416573641309943913383658451409219852933526106735587605884499707827
e=11850552481503020257392808424743510851763548184936536180317707155841959788151862976445957810691568475609821000653594584717037528429828330763571556164988619635320288125983463358648887090031957900011546300841211712664477474767941406651977784177969001025954167441377912326806132232375497798238928464025466905201977180541053129691501120197010080001677260814313906843670652972019631997467352264392296894192998971542816081534808106792758008676039929763345402657578681818891775091140555977382868531202964486261123748663752490909455324860302967636149379567988941803701512680099398021640317868259975961261408500449965277690517
c=4218884541887711839568615416673923480889604461874475071333225389075770098726337046768413570546617180777109293884545400260353306419150066928226964662256930702466709992997796154415790565112167663547017839870351167884417142819504498662037048412313768450136617389372395690363188005647619061128497371121168347810294424378348301835826084732747005110258557662466626720961279087145559906371505117097599774430970980355531235913439823966628008554872896820907555353892843539526041019103819804854883231421963308265517622470779089941078841902464033685762524196275032288319744157255628189204988632871276637699312750636348750883054


请解出明文!!!2、解题方法
exp1:维纳攻击1
# Sage

def rational_to_contfrac(x, y):

    # Converts a rational x/y fraction into a list of partial quotients

    a = x // y

    pquotients =

    while a * y != x:

      x, y = y, x - a * y

      a = x // y

      pquotients.append(a)

    return pquotients

def convergents_from_contfrac(frac):

    # computes the list of convergents using the list of partial quotients

    convs = [];

    for i in range(len(frac)): convs.append(contfrac_to_rational(frac))

    return convs

def contfrac_to_rational(frac):

    # Converts a finite continued fraction to an x/y rational.

    if len(frac) == 0: return (0, 1)

    num = frac[-1]

    denom = 1

    for _ in range(-2, -len(frac) - 1, -1): num, denom = frac * num + denom, num

    return (num, denom)

n = 12238605063252292170613110607692779326628090745751955692266649177882959231822580682548279800443278979485092243645806337103841086023159482786712759291169541633901936290854044069486201989034158882661270017305064348254800318759062921744741432214818915527537124001063995865927527037625277330117588414586505635959411443039463168463608235165929831344586283875119363703480280602514451713723663297066810128769907278246434745483846869482536367912810637275405943566734099622063142293421936734750356828712268385319217225803602442033960930413469179550331907541244416573641309943913383658451409219852933526106735587605884499707827
e=11850552481503020257392808424743510851763548184936536180317707155841959788151862976445957810691568475609821000653594584717037528429828330763571556164988619635320288125983463358648887090031957900011546300841211712664477474767941406651977784177969001025954167441377912326806132232375497798238928464025466905201977180541053129691501120197010080001677260814313906843670652972019631997467352264392296894192998971542816081534808106792758008676039929763345402657578681818891775091140555977382868531202964486261123748663752490909455324860302967636149379567988941803701512680099398021640317868259975961261408500449965277690517
c=4218884541887711839568615416673923480889604461874475071333225389075770098726337046768413570546617180777109293884545400260353306419150066928226964662256930702466709992997796154415790565112167663547017839870351167884417142819504498662037048412313768450136617389372395690363188005647619061128497371121168347810294424378348301835826084732747005110258557662466626720961279087145559906371505117097599774430970980355531235913439823966628008554872896820907555353892843539526041019103819804854883231421963308265517622470779089941078841902464033685762524196275032288319744157255628189204988632871276637699312750636348750883054
def egcd(a, b):

    if a == 0: return (b, 0, 1)

    g, x, y = egcd(b % a, a)

    return (g, y - (b // a) * x, x)

def mod_inv(a, m):

    g, x, _ = egcd(a, m)

    return (x + m) % m

def isqrt(n):

    x = n

    y = (x + 1) // 2

    while y < x:

      x = y

      y = (x + n // x) // 2

    return x

def crack_rsa(e, n):

    frac = rational_to_contfrac(e, n)

    convergents = convergents_from_contfrac(frac)

    for (k, d) in convergents:

      if k != 0 and (e * d - 1) % k == 0:

            phi = (e * d - 1) // k

            s = n - phi + 1

            # check if x*x - s*x + n = 0 has integer roots

            D = s * s - 4 * n

            if D >= 0:

                sq = isqrt(D)

                if sq * sq == D and (s + sq) % 2 == 0: return d

d = crack_rsa(e, n)
m = hex(pow(c, d, n))
print(bytes.fromhex(m))
#FSCTF{Y0u_ar3_s0_C001}exp2:维纳攻击2
import gmpy2

def transform(x, y):# 使用辗转相处将分数 x/y 转为连分数的形式
    res = []
    while y:
      res.append(x // y)
      x, y = y, x % y
    return res


def continued_fraction(sub_res):
    numerator, denominator = 1, 0
    for i in sub_res[::-1]:# 从sublist的后面往前循环
      denominator, numerator = numerator, i * numerator + denominator
    return denominator, numerator# 得到渐进分数的分母和分子,并返回


# 求解每个渐进分数
def sub_fraction(x, y):
    res = transform(x, y)
    res = list(map(continued_fraction, (res for i in range(1, len(res)))))# 将连分数的结果逐一截取以求渐进分数
    return res


def get_pq(a, b, c):# 由p+q和pq的值通过维达定理来求解p和q
    par = gmpy2.isqrt(b * b - 4 * a * c)# 由上述可得,开根号一定是整数,因为有解
    x1, x2 = (-b + par) // (2 * a), (-b - par) // (2 * a)
    return x1, x2


def wienerAttack(e, n):
    for (d, k) in sub_fraction(e, n):# 用一个for循环来注意试探e/n的连续函数的渐进分数,直到找到一个满足条件的渐进分数
      if k == 0:# 可能会出现连分数的第一个为0的情况,排除
            continue
      if (e * d - 1) % k != 0:# ed=1 (mod φ(n)) 因此如果找到了d的话,(ed-1)会整除φ(n),也就是存在k使得(e*d-1)//k=φ(n)
            continue

      phi = (e * d - 1) // k# 这个结果就是 φ(n)
      px, qy = get_pq(1, n - phi + 1, n)
      if px * qy == n:
            p, q = abs(int(px)), abs(int(qy))# 可能会得到两个负数,负负得正未尝不会出现
            d = gmpy2.invert(e, (p - 1) * (q - 1))# 求ed=1 (modφ(n))的结果,也就是e关于 φ(n)的乘法逆元d
            return d
    print("该方法不适用")

n = 12238605063252292170613110607692779326628090745751955692266649177882959231822580682548279800443278979485092243645806337103841086023159482786712759291169541633901936290854044069486201989034158882661270017305064348254800318759062921744741432214818915527537124001063995865927527037625277330117588414586505635959411443039463168463608235165929831344586283875119363703480280602514451713723663297066810128769907278246434745483846869482536367912810637275405943566734099622063142293421936734750356828712268385319217225803602442033960930413469179550331907541244416573641309943913383658451409219852933526106735587605884499707827
e=11850552481503020257392808424743510851763548184936536180317707155841959788151862976445957810691568475609821000653594584717037528429828330763571556164988619635320288125983463358648887090031957900011546300841211712664477474767941406651977784177969001025954167441377912326806132232375497798238928464025466905201977180541053129691501120197010080001677260814313906843670652972019631997467352264392296894192998971542816081534808106792758008676039929763345402657578681818891775091140555977382868531202964486261123748663752490909455324860302967636149379567988941803701512680099398021640317868259975961261408500449965277690517
c=4218884541887711839568615416673923480889604461874475071333225389075770098726337046768413570546617180777109293884545400260353306419150066928226964662256930702466709992997796154415790565112167663547017839870351167884417142819504498662037048412313768450136617389372395690363188005647619061128497371121168347810294424378348301835826084732747005110258557662466626720961279087145559906371505117097599774430970980355531235913439823966628008554872896820907555353892843539526041019103819804854883231421963308265517622470779089941078841902464033685762524196275032288319744157255628189204988632871276637699312750636348750883054

d = wienerAttack(e, n)
print("d=", d)
m = hex(pow(c, d, n))
print(bytes.fromhex(m))
#FSCTF{Y0u_ar3_s0_C001}Do you know gcd?

1、题目信息
from Crypto.Util.number import *
from secret import flag

m1=bytes_to_long(flag[:16])
m2=bytes_to_long(flag)
p=getPrime(1024)
q1=getPrime(1024)
q2=getPrime(1024)
n1=p*q1
n2=p*q2
e=65537
c1=pow(m1,e,n1)
c2=pow(m2,e,n2)
print("n1=",n1)
print("n2=",n2)
print("c1=",c1)
print("c2=",c2)
'''
n1= 18680935400842120133090782991548100098299141114788036098274292600814484762178879421175852824971602717084073867867453382415307589970440719890918576225495401632854107018246844209327118177917122236073227158593514362850629722223228335334773008682775987859295083444638923726449899310854161394586430943134469559429878238769266114132469166535509030877235272476877484918308883799496627699789051809542538091061550107526246728583019140703765888157806778516567048103700384849598143249322109207879381251223776896702362630437178664824125387477797876186939235800859102380783259361745143574493440078787931593394188675093506492640857
n2= 16308523133405725830120564525574438512803584148781960516042054284309437381876822602134185065101371986717984978566359252072738078020261823966208153922611063201149105749778596739692554295573408850719208215646167050188830459343054219856901871953140988948482577813730729085764541988120049026971705499798003225755018687242522370406495429425494022876627543617474873929054728724093702291448754458748923218635900061398716191201846139296921753782690468189409101899415028480878296408735247604084627019116374444335509072590669239349212479592499426230525792270750612371117196200786891891430446212938482959351978202358044864822577
c1= 534518909595318304521410713148076850830155521838755402438490325620155197496935820831936109252194297244161393310730073882257949954815312409974998733265641354273665213856408848764503848122264972023143474923678585167025591255034150826271791019266426616987355463111138963331008761826310757292765842789380409826387579098421126952331558360737102888876551724241978020305977032047901621477384392409864427091911872691182528938458750707982564581322551517287491916691010743390992018974168703956622998928457142606354825714033609199676987795174032254878017883605565760275857658822315970522114838062469258676628619381342357632179
c2= 10248394002302905069278122013496854496130190499518622376819239887579692634750808499513497018453473232140518824608976734237637842228035017757831938865937098325684711995382081489403971465596662585196007547659143066184546400992333479193424580690897692586491475768279754939199148642035267049092880715299621206567123356521609120801306358100326600900326310677054810032471472266402660807205675696110133573150125117412696328434523507708110949743705536889950671778501402435457354251761692098671783596194430798692942013503015764266392551048702428063161786512924608239609802040937400619384828550050291094616346317726139970219621
'''2、题目信息
共e攻击
import gmpy2
import binascii

e = 65537
n1= 18680935400842120133090782991548100098299141114788036098274292600814484762178879421175852824971602717084073867867453382415307589970440719890918576225495401632854107018246844209327118177917122236073227158593514362850629722223228335334773008682775987859295083444638923726449899310854161394586430943134469559429878238769266114132469166535509030877235272476877484918308883799496627699789051809542538091061550107526246728583019140703765888157806778516567048103700384849598143249322109207879381251223776896702362630437178664824125387477797876186939235800859102380783259361745143574493440078787931593394188675093506492640857
n2= 16308523133405725830120564525574438512803584148781960516042054284309437381876822602134185065101371986717984978566359252072738078020261823966208153922611063201149105749778596739692554295573408850719208215646167050188830459343054219856901871953140988948482577813730729085764541988120049026971705499798003225755018687242522370406495429425494022876627543617474873929054728724093702291448754458748923218635900061398716191201846139296921753782690468189409101899415028480878296408735247604084627019116374444335509072590669239349212479592499426230525792270750612371117196200786891891430446212938482959351978202358044864822577
c1= 534518909595318304521410713148076850830155521838755402438490325620155197496935820831936109252194297244161393310730073882257949954815312409974998733265641354273665213856408848764503848122264972023143474923678585167025591255034150826271791019266426616987355463111138963331008761826310757292765842789380409826387579098421126952331558360737102888876551724241978020305977032047901621477384392409864427091911872691182528938458750707982564581322551517287491916691010743390992018974168703956622998928457142606354825714033609199676987795174032254878017883605565760275857658822315970522114838062469258676628619381342357632179
c2= 10248394002302905069278122013496854496130190499518622376819239887579692634750808499513497018453473232140518824608976734237637842228035017757831938865937098325684711995382081489403971465596662585196007547659143066184546400992333479193424580690897692586491475768279754939199148642035267049092880715299621206567123356521609120801306358100326600900326310677054810032471472266402660807205675696110133573150125117412696328434523507708110949743705536889950671778501402435457354251761692098671783596194430798692942013503015764266392551048702428063161786512924608239609802040937400619384828550050291094616346317726139970219621

p = gmpy2.gcd(n1, n2)
q = n2 // p# 这里用n2求第二部分
phi = (p - 1) * (q - 1)

d = gmpy2.invert(e, phi)
m = gmpy2.powmod(c2, d, n2)

print(binascii.unhexlify(hex(m)))

q = n1 // p# 这里用n1求第一部分
phi = (p - 1) * (q - 1)

d = gmpy2.invert(e, phi)
m = gmpy2.powmod(c1, d, n1)

print(binascii.unhexlify(hex(m)))
#FSCTF{0hN0_Y0u_f1nd_th3_gcd!}埃塞克的秘密

1、题目信息
埃塞克先生将自己的秘密藏在盒子里并交给了ROT保管埃塞克先生将自己的秘密藏在盒子里并交给了ROT保管,埃塞克先生在盒子上留下了这样一串数字:
117 36 114 37 117 76 37 57 111 63 60 48 74 64 70 782、解题方法
cyber一把梭
https://img2023.cnblogs.com/blog/3167109/202310/3167109-20231023183813132-1881118325.png
RSA签到

1、题目信息
from Crypto.Util.number import *from secret import flagm = bytes_to_long(flag)assert m.bit_length()> kbits)
页: [1]
查看完整版本: FSCTF 2023(公开赛道)CRYPTO WP