首页 > 其他分享 >xyctf

xyctf

时间:2024-05-13 09:34:26浏览次数:12  
标签:return list xyctf flag input print import

Crypto

babyRSAMAX

souce.py

from Crypto.Util.number import *
from gmpy2 import *
from random import choice
flag = b'XYCTF{******}'
e = '?'
def getBabyPrime(nbits):
    while True:
        p = 1
        while p.bit_length() <= nbits:
            p *= choice(sieve_base)

        if isPrime(p+1):
            return p+1
p = getBabyPrime(512)
q = getBabyPrime(512)
n = p*q
gift1 = (pow(p,e,n)-pow(q,e,n)) % n
gift2 = pow(p+q,e,n)
t = 65537
x = bytes_to_long(e)
y = pow(x, t, n)
m = bytes_to_long(flag)
c = powmod(m, e, n)
print(f'n = {n}')
print(f'gift1 = {gift1}')
print(f'gift2 = {gift2}')
print(f'c = {c}')
print(f'y = {y}')
'''
n = 39332423872740210783246069030855946244104982381157166843977599780233911183158560901377359925435092326653303964261550158658551518626014048783435245471536959844874036516931542444719549997971482644905523459407775392702211086149279473784796202020281909706723380472571862792003687423791576530085747716706475220532321
gift1 = 4549402444746338327349007235818187793950285105091726167573552412678416759694660166956782755631447271662108564084382098562999950228708300902201571583419116299932264478381197034402338481872937576172197202519770782458343606060544694608852844228400457232100904217062914047342663534138668490328400022651816597367310
gift2 = 111061215998959709920736448050860427855012026815376672067601244053580566359594802604251992986382187891022583247997994146019970445247509119719411310760491983876636264003942870756402328634092146799825005835867245563420135253048223898334460067523975023732153230791136870324302259127159852763634051238811969161011462
c = 16938927825234407267026017561045490265698491840814929432152839745035946118743714566623315033802681009017695526374397370343984360997903165842591414203197184946588470355728984912522040744691974819630118163976259246941579063687857994193309554129816268931672391946592680578681270693589911021465752454315629283033043
y = 1813650001270967709841306491297716908969425248888510985109381881270362755031385564927869313112540534780853966341044526856705589020295048473305762088786992446350060024881117741041260391405962817182674421715239197211274668450947666394594121764333794138308442124114744892164155894256326961605137479286082964520217
'''

solve_idea

首先看到 gift1,和 gift2

\[gift1 = (p^e - q^e) (mod \quad n) \]

\[gift2 = (p+q)^e(mod \quad n) \]

其中 gift2 可以有如下转换,对公式展开

\[gift2 = p^e + q^e + k*n = p^e + q^e (mod\quad n) \]

对两式进行联立,直接对 gift1+gift2n 取公因数,即可得到 pq,也可得到 e

from Crypto.Util.number import *
import math
import gmpy2
t = 65537
n = 39332423872740210783246069030855946244104982381157166843977599780233911183158560901377359925435092326653303964261550158658551518626014048783435245471536959844874036516931542444719549997971482644905523459407775392702211086149279473784796202020281909706723380472571862792003687423791576530085747716706475220532321
gift1 = 4549402444746338327349007235818187793950285105091726167573552412678416759694660166956782755631447271662108564084382098562999950228708300902201571583419116299932264478381197034402338481872937576172197202519770782458343606060544694608852844228400457232100904217062914047342663534138668490328400022651816597367310
gift2 = 111061215998959709920736448050860427855012026815376672067601244053580566359594802604251992986382187891022583247997994146019970445247509119719411310760491983876636264003942870756402328634092146799825005835867245563420135253048223898334460067523975023732153230791136870324302259127159852763634051238811969161011462
c = 16938927825234407267026017561045490265698491840814929432152839745035946118743714566623315033802681009017695526374397370343984360997903165842591414203197184946588470355728984912522040744691974819630118163976259246941579063687857994193309554129816268931672391946592680578681270693589911021465752454315629283033043
y = 1813650001270967709841306491297716908969425248888510985109381881270362755031385564927869313112540534780853966341044526856705589020295048473305762088786992446350060024881117741041260391405962817182674421715239197211274668450947666394594121764333794138308442124114744892164155894256326961605137479286082964520217
p = math.gcd(gift1+gift2,n)
q = n // p
assert n == p*q
phi = (p-1)*(q-1)
d = gmpy2.invert(t,phi)
print(long_to_bytes(pow(y,d,n)))
b'XYCTF{e==4096}'

得到 e = 4096,就必须考虑 ephi 不互素的问题,要求如下

\[m ^ e = c(mod \quad n) \]

我们可知如下条件

\[\because k1*e + k2*phi = gcd(e,phi) \]

\[\therefore e*d = gcd(e,phi) (mod \quad n) \]

\[\therefore c^d = m^{e*d} = m^{gcd(e,phi)} (mod \quad n) \]

此时的 d 满足如下条件

\[d * \frac {e}{gcd(e,phi)} + k2 * \frac{phi}{gcd(e,phi)} = 1 \]

之后就是直接求根就好

solve.py

from Crypto.Util.number import *
import math
import gmpy2
n = 39332423872740210783246069030855946244104982381157166843977599780233911183158560901377359925435092326653303964261550158658551518626014048783435245471536959844874036516931542444719549997971482644905523459407775392702211086149279473784796202020281909706723380472571862792003687423791576530085747716706475220532321
gift1 = 4549402444746338327349007235818187793950285105091726167573552412678416759694660166956782755631447271662108564084382098562999950228708300902201571583419116299932264478381197034402338481872937576172197202519770782458343606060544694608852844228400457232100904217062914047342663534138668490328400022651816597367310
gift2 = 111061215998959709920736448050860427855012026815376672067601244053580566359594802604251992986382187891022583247997994146019970445247509119719411310760491983876636264003942870756402328634092146799825005835867245563420135253048223898334460067523975023732153230791136870324302259127159852763634051238811969161011462
c = 16938927825234407267026017561045490265698491840814929432152839745035946118743714566623315033802681009017695526374397370343984360997903165842591414203197184946588470355728984912522040744691974819630118163976259246941579063687857994193309554129816268931672391946592680578681270693589911021465752454315629283033043
y = 1813650001270967709841306491297716908969425248888510985109381881270362755031385564927869313112540534780853966341044526856705589020295048473305762088786992446350060024881117741041260391405962817182674421715239197211274668450947666394594121764333794138308442124114744892164155894256326961605137479286082964520217
p = 166353789373057352195268575168397750362643822201253508941052835945420624983216456266478176579651490080696973849607356408696043718492499993062863415424578199
q = 236438400477521597922950445153796265199072404577183190953114805170522875904551780358338769440558816351105253794964040981919231484098097671084895302287425479
t = 65537
phi = (p-1)*(q-1)
d1 = gmpy2.invert(t,(p-1)*(q-1))
e = pow(y,d1,n)
print(long_to_bytes(e))
e = 4096
gcd = math.gcd(e,phi)
d = gmpy2.invert(e//gcd,phi//gcd)
m1 = pow(c,d,n)
m = gmpy2.iroot(m1,gcd)[0]
print(long_to_bytes(m))
b'XYCTF{Rabin_is_so_biggggg!}'

Complex_dlp

souce.py

from Crypto.Util.number import *
from secrets import flag

class Complex:
    def __init__(self, re, im):
        self.re = re
        self.im = im

    def __mul__(self, c):
        re_ = self.re * c.re - self.im * c.im
        im_ = self.re * c.im + self.im * c.re
        return Complex(re_, im_)

    def __str__(self):
        if self.im == 0:
            return str(self.re)
        elif self.re == 0:
            if abs(self.im) == 1:
                return f"{'-' if self.im < 0 else ''}i"
            else:
                return f"{self.im}i"
        else:
            return f"{self.re} {'+' if self.im > 0 else '-'} {abs(self.im)}i"


def complex_pow(c, exp, n):
    result = Complex(1, 0)
    while exp > 0:
        if exp & 1:
            result = result * c
            result.re = result.re % n
            result.im = result.im % n
        c = c * c
        c.re = c.re % n
        c.im = c.im % n
        exp >>= 1
    return result


flag = flag.strip(b"XYCTF{").strip(b"}")
p = 1127236854942215744482170859284245684922507818478439319428888584898927520579579027
g = Complex(3, 7)
x = bytes_to_long(flag)
print(complex_pow(g, x, p))
# 5699996596230726507553778181714315375600519769517892864468100565238657988087817 + 198037503897625840198829901785272602849546728822078622977599179234202360717671908i

solve_idea

在 Complex 类中,定义了初始化复数,复数的乘法,复数的字符串化;其次就是 complex_pow 函数,读明白函数就可以发现,c 在每一次的循环中,都对自己做平方,跟随 exp 的每一位的权,且当 exp 的某一位是 1 的时候,result 与 c 做乘法,为 0,则不做处理,不难发现满足如下条件

\[result = c^{exp}(mod \quad n) \]

就是典型的离散对数问题,接下来就是如何将其由复数域转换到实数域中,可以想到共轭复数

\[假设 (m+ni)^x = a+bi \\ (m-i)^x = a+ ci \]

\[则 \\(m+ni)^x*(m-ni)^x = a^2 - b*c + (a*b+a*c)i  \]

\[\because 他们是共轭复数 \\ \therefore b = -c \\ \therefore 该式变为了  a^2 + b^2 \]

这样我们就可以构造实数域上的离散对数,(3-7i)*(3+7i) = 58

solve.py

from Crypto.Util.number import *
p = 1127236854942215744482170859284245684922507818478439319428888584898927520579579027
g = 58
y = 5699996596230726507553778181714315375600519769517892864468100565238657988087817**2 + 198037503897625840198829901785272602849546728822078622977599179234202360717671908**2
x=discrete_log(y,mod(g,p))
print(long_to_bytes(x))
b'___c0mp13x_d1p_15_3@5y_f0r_y0u___'

factor1

souce.py

import gmpy2
import hashlib
from Crypto.Util.number import *

p = getPrime(512)
q = getPrime(512)
d = getPrime(512)
e = gmpy2.invert(d, (p**3 - 1) * (q**3 - 1))
flag = "XYCTF{" + hashlib.md5(str(p + q).encode()).hexdigest() + "}"
print(e)
print(p * q)
# 172005065945326769176157335849432320425605083524943730546805772515111751580759726759492349719668775270727323745284785341119685198468883978645793770975366048506237371435027612758232099414404389043740306443065413069994232238075194102578269859784981454218948784071599231415554297361219709787507633404217550013282713899284609273532223781487419770338416653260109238572639243087280632577902857385265070736208291583497988891353312351322545840742380550393294960815728021248513046077985900158814037534487146730483099151396746751774427787635287611736111679074330407715700153025952858666841328055071403960165321273972935204988906850585454805923440635864200149694398767776539993952528995717480620593326867245714074205285828967234591508039849777840636255379730281105670496110061909219669860172557450779495125345533232776767292561378244884362014224844319802810586344516400297830227894063759083198761120293919537342405893653545157892446163
# 99075185389443078008327214328328747792385153883836599753096971412377366865826254033534293886034828804219037466246175526347014045811852531994537520303063113985486063022444972761276531422538694915030159420989401280012025249129111871649831185047820236417385693285461420040134313833571949090757635806658958193793

solve_idea

我们查看 en 的位数

因为

\[e*d = 1 mod(p^3-1)*(q^3-1) \\ ed = 1 + k(p^3-1)*(q^3-1) \\ ed \approx kn^3 \]

我们可以想到维纳攻击,然后使用多项式求解

solve.py

import hashlib
from xenny.ctf.crypto.modern.asymmetric.rsa import wiener
import gmpy2
from sympy import *
e = 172005065945326769176157335849432320425605083524943730546805772515111751580759726759492349719668775270727323745284785341119685198468883978645793770975366048506237371435027612758232099414404389043740306443065413069994232238075194102578269859784981454218948784071599231415554297361219709787507633404217550013282713899284609273532223781487419770338416653260109238572639243087280632577902857385265070736208291583497988891353312351322545840742380550393294960815728021248513046077985900158814037534487146730483099151396746751774427787635287611736111679074330407715700153025952858666841328055071403960165321273972935204988906850585454805923440635864200149694398767776539993952528995717480620593326867245714074205285828967234591508039849777840636255379730281105670496110061909219669860172557450779495125345533232776767292561378244884362014224844319802810586344516400297830227894063759083198761120293919537342405893653545157892446163
n = 99075185389443078008327214328328747792385153883836599753096971412377366865826254033534293886034828804219037466246175526347014045811852531994537520303063113985486063022444972761276531422538694915030159420989401280012025249129111871649831185047820236417385693285461420040134313833571949090757635806658958193793
def transfer(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]:
        denominator,numerator = numerator,i*numerator+denominator
    return denominator,numerator
def sub_fraction(x,y):
    res = transfer(x,y)
    res=list(map(continued_fraction,(res[0:i] for i in range(1,len(res))))) _#将连分数的结果逐一截取以求渐进分数_
_    _return res
def get_pq(a,b,c):
    par = gmpy2.isqrt(b*b-4*a*c)
    x1,x2 = (-b+par)//(2*a),(b+par)//(2*a)
def wienerAttack(e,n):
    a = []
    for (d,k) in sub_fraction(e,n):
        if k == 0:
            continue
        if (e*d - 1)%k != 0:
            continue
        phi = (e*d - 1)//k
        a.append(phi)
        print(phi)
    return a
phi = wienerAttack(e,n**3)
pq = n**3+1-phi[3]
x = symbols('x')
s = solve(x**3-3*n*x-pq)
m  = s[0]
flag = "XYCTF{" + hashlib.md5(str(m).encode()).hexdigest() + "}"
print(flag)
XYCTF{a83211a70e18145a59671c08ddc67ba4}

x0r

source.py

from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import os

flag = open("flag.txt", "rb").read()
key = os.urandom(16)
iv = os.urandom(16)
flag = pad(flag, 16)

def aes_encrypt(key, plaintext):
    cipher = AES.new(key, AES.MODE_ECB)
    return cipher.encrypt(plaintext)

def encrypt(key, plaintext, iv):
    ciphertext = b""
    for i in range(0, len(plaintext), AES.block_size):
        key_block = aes_encrypt(key, iv)
        ciphertext_block = bytes(
            [plaintext[i + j] ^ key_block[j] for j in range(AES.block_size)]
        )
        ciphertext += ciphertext_block
        iv = key_block
    return ciphertext
while 1:
    try:
        print("1.print\n2.input\n3.exit")
        a = input("> ")
        if a == "1":
            print((iv + encrypt(key, flag, iv)).hex())
        elif a == "2":
            ivs = bytes.fromhex(input("iv: "))
            inputs = bytes.fromhex(input("message: "))
            print(encrypt(key, inputs, ivs).hex())
        elif a == "3":
            exit(0)
        else:
            print("You need input 1,2,3")
    except:exit(0)

solve_idea

首先 nc 一下,查看加密以后的密文

e48d07626a1b48ea539adff062ca407d1739e4b3b7c42366be81a81d1a730b85b52b5b0e38068de8c6978851d1ab55d71df2db406af0bc54af7e46e6337fa15e

一共 128 个字符,即 64 个字节,刨去 iv,因为加密后的密文和明文长度一致,所以 flag 有 48 字节

加密如下:

我们可以得到 iv 和 cipher,要求得 flag,就必须得到几轮 key_block,我们可以看到选项二,可以输入任意明文,得到输出,我们可以利用已知明文攻击拿到 key_block(iv 一致,该值一致)

solve.py

from Crypto.Util.number import *
_#import os_
_#plantext = os.urandom(48)_
enc = 0xe48d07626a1b48ea539adff062ca407d1739e4b3b7c42366be81a81d1a730b85b52b5b0e38068de8c6978851d1ab55d71df2db406af0bc54af7e46e6337fa15e
enc = long_to_bytes(enc)
iv = enc[:16]
flag_cipher = enc[16:]
plantext = b'1\xf0\xf3E\x8b/\xbd\x9dNr\xb5\xe5\x9e `\xb7t\xa2\xdc;\x9a\x00X\x0e\xe4\xf6\xd28\x0ev\x12H\x1et\xbb/^\xbb\xd9\x17\x80\xa6B\x1d\xc9\x02&\xbc'
cipher = 0x7e9054a27a90a99ac5c67b9eb5314657a5bdb0189634e4840f036d59eef023fb3be5510d0172577549e979f1fe7983e6
plantext = bytes_to_long(plantext)
key_block = plantext^cipher
flag = bytes_to_long(flag_cipher) ^ key_block
print(long_to_bytes(flag))
b'XYCTF{7a55ff1b-ed47-421b-b701-dd8c1b5926f1}\n\x04\x04\x04\x04'

反方向的密码 相思

souce.py

from Crypto.Util.number import *
import hashlib
from secrets import flag

def hash(x):
    return hashlib.sha256(x.encode()).digest()

def pad(message):
    return message + hash(str(len(message)))


m = bytes_to_long(pad(flag))
p = getStrongPrime(512)
q = getStrongPrime(512)
n = p * q
e = 3
print(pow(m, e, n))
print(n)
# 120440199294949712392334113337541924034371176306546446428347114627162894108760435789068328282135879182130546564535108930827440004987170619301799710272329673259390065147556073101312748104743572369383346039000998822862286001416166288971531241789864076857299162050026949096919395896174243383291126202796610039053
# 143413213355903851638663645270518081058249439863120739973910994223793329606595495141951165221740599158773181585002460087410975579141155680671886930801733174300593785562287068287654547100320094291092508723488470015821072834947151827362715749438612812148855627557719115676595686347541785037035334177162406305243

solve_idea

Coppersmith 定理指出在一个 e 阶的 mod_n_ 多项式 f(x) 中,如果有一个根小于 n^{1/e} ,就可以运用一个 O(log_n_) 的算法求出这些根。

而我们需要将 m 拆分为几个部分,把已知的位数利用起来,通过爆破长度,给出 m 的多项式

然后来进行运算

solve.py

from Crypto.Util.number import *
import hashlib
import gmpy2
c = 120440199294949712392334113337541924034371176306546446428347114627162894108760435789068328282135879182130546564535108930827440004987170619301799710272329673259390065147556073101312748104743572369383346039000998822862286001416166288971531241789864076857299162050026949096919395896174243383291126202796610039053
n = 143413213355903851638663645270518081058249439863120739973910994223793329606595495141951165221740599158773181585002460087410975579141155680671886930801733174300593785562287068287654547100320094291092508723488470015821072834947151827362715749438612812148855627557719115676595686347541785037035334177162406305243
a = b"XYCTF{"
b = bytes_to_long(a)
e = 3
R.<x> = Zmod(n)[]
def hash(x):
    return hashlib.sha256(x.encode()).digest()
for k in range(10,60):#爆破flag的长度
    dex = bytes_to_long(hash(str(k+7)))
    f = ( b * 256^(k+33) + x * 256^(33) + 125*256^32 + dex) ^ e - c#构造的多项式
    f = f.monic()#将多项式的系数变成1
    root = f.small_roots(X = 2 ^ (8 * k))#求最小的根,其中X是根取值的上界
    if(root):
        print(root)
        break
58964190787951927773278389967057377362495121527440001979648729026891046689
from Crypto.Util.number import *

a = 58964190787951927773278389967057377362495121527440001979648729026891046689
b = str(long_to_bytes(a))[2:-1]
print("XYCTF{"+b+"}")
#XYCTF{!__d3ng__hu0__1@n__3h@n__Chu__!}

happy_to_solve1

souce.py

from Crypto.Util.number import *
import sympy
from secrets import flag


def get_happy_prime():
    p = getPrime(512)
    q = sympy.nextprime(p ^ ((1 << 512) - 1))
    return p, q

m = bytes_to_long(flag)
p, q = get_happy_prime()
n = p * q
e = 65537
print(n)
print(pow(m, e, n))
# 24852206647750545040640868093921252282805229864862413863025873203291042799096787789288461426555716785288286492530194901130042940279109598071958012303179823645151637759103558737126271435636657767272703908384802528366090871653024192321398785017073393201385586868836278447340624427705360349350604325533927890879
# 14767985399473111932544176852718061186100743117407141435994374261886396781040934632110608219482140465671269958180849886097491653105939368395716596413352563005027867546585191103214650790884720729601171517615620202183534021987618146862260558624458833387692782722514796407503120297235224234298891794056695442287

Solve_idea

查看代码可知,该代码中 p 是 512 位的数字,q 的得出如下:

首先对 p 和(1<<512) - 1 进行异或,由于该值是 512 个 1 组成,所以 p 的每一位均被反转,假设该值为 p1,q 就是 p1 的下一个素数,两个素数的间隔可以看这个

我们就可以了解 q 与 p1 的值特别接近,可以利用这个点爆破,所以 p+q≈(1<<512)-1(大于关系)

\[phi = (p-1)*(q-1) = p*q - (p+q) + 1 \]

我们可以知道 p+q 的近似值,那么可以轻易爆破出 phi 的值,思路就明了了

solve.py

import gmpy2
from Crypto.Util.number import *

n = 24852206647750545040640868093921252282805229864862413863025873203291042799096787789288461426555716785288286492530194901130042940279109598071958012303179823645151637759103558737126271435636657767272703908384802528366090871653024192321398785017073393201385586868836278447340624427705360349350604325533927890879
c = 14767985399473111932544176852718061186100743117407141435994374261886396781040934632110608219482140465671269958180849886097491653105939368395716596413352563005027867546585191103214650790884720729601171517615620202183534021987618146862260558624458833387692782722514796407503120297235224234298891794056695442287
e = 65537
for i in range(1,10000):
    p = 2**512
    t = p+i
    d = gmpy2.invert(e,n-t+1)
    m = pow(c,d,n)
    s = long_to_bytes(m)
    if("XYCTF" in str(s)):
        print(s)
        break

Signup

source.py

from Crypto.Util.number import *
from tqdm import *
import gmpy2
flag=b'XYCTF{uuid}'
flag=bytes_to_long(flag)
leak=bin(int(flag))
while 1:
    leak += "0"
    if len(leak) == 514:
        break

def swap_bits(input_str):
    input_list = list(input_str[2:])
    length = len(input_list)

    for i in range(length // 2):
        temp = input_list[i]
        input_list[i] = input_list[length - 1 - i]
        input_list[length - 1 - i] = temp

    return ''.join(input_list)

input_str = leak
result = swap_bits(input_str)
a=result

def custom_add(input_str):
    input_list = list(input_str)
    length = len(input_list)
    
    for i in range(length):
        input_list[i] = str((int(input_list[i]) + i + 1) % 10)

    result = ''.join(input_list)
    return result


input_str = a
result = custom_add(input_str)
b=result
print(b)
#12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456799123455788902334667801123556899022346778001245568890233467790012355689911335667890134457789122355779001335668890133467799112455779902334667801133566889113346778001344567990233457790013356688911334677891134457889122355779001335668891133566799012455678912234677900134456899012356678011344568891223566890113455689911234677891224556899023

solve_idea

Solve.py chatgtp

from Crypto.Util.number import *
def swap_bits(input_str):_#这边直接套⽤对应的脚本_
_    _input_list = list(input_str[2:])
    length = len(input_list)
    for i in range(length // 2):
        temp = input_list[i]
        input_list[i] = input_list[length - 1 - i]
        input_list[length - 1 - i] = temp
    return ''.join(input_list)
b =12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567891134567799013445678012234677900124457889122356679011344568991223556890012355788901335667901134457780122355788001334568991233566789113445678012235578800133557889123356679911344567991223557880012455788911335667801124556780122355788001334568990223566780012455679902335667801133457889123356678001245578801233467789112355779912234577990233556780113
list_b = list(str(b))
input_list = []
for i in range(len(list_b)):
    input_list.append(str((int(list_b[i]) - i - 1) % 10))
input_str = ''.join(input_list)
result1 = swap_bits(input_str)
result1 = result1.rstrip('0')
flag = int(result1, 2)
print(long_to_bytes(flag))

fakeRSA

souce.py

from Crypto.Util.number import *

flag = b'XYCTF{******}'
n = ZZ(bytes_to_long(flag))
p = getPrime(int(320))
print(p)

G = Zmod(p)

def function(X, Y, Z):
    def part(a, b, c):
        return vector([9 * a - 36 * c, 6 * a - 27 * c, b])
    def parts(n):
        Gx.<a, b, c> = G[]
        if n == 0: return vector([a, b, c])
        mid = parts(n // 2)
        result = mid(*mid)
        if n % 2 == 0: return result
        else: return part(*result)
    return parts(n)(X, Y, Z)

print(function(69, 48, 52))


#1849790472911267366045392456893126092698743308291512220657006129900961168811898822553602045875909
#(1431995965813617415860695748430644570118959991271395110995534704629241309597572003500157255135707, 1011565891130611736600822618382801465506651972373410962205810570075870804325974377971089090196019, 784497518859893244278116222363814433595961164446277297084989532659832474887622082585456138030246)

solve_idea

factor3

source.py

from Crypto.Util.number import *
import random

flag = b'XYCTF{*****}'
m = bytes_to_long(flag)
def gainPrime():
    while True:
        x = random.getrandbits(256)
        y = random.getrandbits(256)

        if y % 2 == 0:
            continue 
        p = x ** 3 + 3 * y ** 3
        if p.bit_length() == 768 and p % 2 == 1 and isPrime(p):
            return p

p, q = gainPrime(), gainPrime()
N = p * q
phi = (p ** 2 + p + 1) * (q ** 2 + q + 1)
d = getPrime(320)
e = inverse(d, phi)
c = d**2^m

print(f"N: {N}")
print(f"e: {e}")
print(f"c: {c}")

N: 913125842482770239379848062277162627509794409924607555622246822717218133091223291889541294440266178282194506242444509803611492259403578922020590849630191477864719052980160940803309686069818208833547621252544423652489179493083138385424424384165228024273745733240109761707533778691158938848158094054261174692601673435971526522219273943464877956131040249169850420336023942653021547841666224446678539579529590840999008107782784268926145671962239929431694391039559247
e: 494518390582436635999115147756676313570637682518235195828939117782099618734167908630788943568232122157772909140885391963441876427590731524706959546524212914108888799081844320513851526790475333924396837458796755678072486028072639014677580265244176441153444956871730684233063789931539669072735599696830757690822185323538738397827461580678488181113667710378657058297572328491762536595872579603698945272140918157163640403488075948987156585480146162739943419183496337465468187233821931312507662218106713861638334075899266373256620752680354704533272722692596941861606161634082613228896420520465402725359166156632884432690715903666803067996854084671477445131853993177110154928274312496230096270510089973592664248613332000290545537840595645944390047611474888693558676781309912289044962293014118087259307560444929227407113819165713213046898243995956550944640168932947118400215917515277554126694376415569909534496134700668701465649939
c: 4450931337369461482106945992542133557585962894030505065110870389112565329875502952762182372926117037373210509516570958483606566274369840551132381128665744266165792377925899683228751870742727716

solve_idea

solve.py

happy_to_solve2

Random_rr

easy_ecc

LCG_and_HNP

铜匠

happy_to_solve3

标签:return,list,xyctf,flag,input,print,import
From: https://www.cnblogs.com/zMeedA/p/18188607

相关文章

  • [XYCTF] fastfastfast
    [XYCTF]fastfastfastUAF|fast_bin_attack|tcache|leak_libc[*]'/home/bamuwe/fastfastfast/vuln'Arch:amd64-64-littleRELRO:PartialRELROStack:CanaryfoundNX:NXenabledPIE:NoPIE(0x3fd000)$chec......
  • XYCTF pwn部分题解 (部分题目详解)
    hello_world(签到)思路:✅这道题就是利用printf函数泄露libc的基地址,然后再次进行栈溢出通过system,/bin/sh来获取shellwp:invisible_flag思路:✅题目提示orw,那我们先看看是否开了沙盒那么是开了沙盒的,试试orw读取flag虽然保护全开但是程序会执行我们写的shellcdoe那么就可......
  • [pwn]XYCTF 2024 个人WriteUp
    目录XYCTF2024WriteUp>pwn1.hello_world(签到)2.invisible_flag3.static_link由于本人菜鸡和时间问题,只打了前两周,打出了pwn的三道简单题目,记录自己的做题过程,如何后续复现可能也会更新。XYCTF2024WriteUp>pwn1.hello_world(签到)常规checksecIDA反编译进入主函数发......
  • XYCTF2024-web-wp
    怎么全是傻逼绕过题。不想评价,就随便打着玩,除了最后一道java反序列化搞心态,其他的ak了:简单题不想说,http注意一下代理是用Via就行,warmup直接:http://xyctf.top:37034/?val1=240610708&val2=QNKCDZO&md5=0e215962017&XYCTF=240610708&XY=240610708LLeeevvveeelll222.phpget......
  • XYctf happy_to_solve wp
    题目如下点击查看代码fromCrypto.Util.numberimport*importsympyfromsecretsimportflagdefget_happy_prime():p=getPrime(512)q=sympy.nextprime(p^((1<<512)-1))returnp,qm=bytes_to_long(flag)p,q=get_happy_prime()n=p*......
  • CTF练习日记——[GXYCTF2019]Ping Ping Ping 1
    首先尝试一下分号有没有被过滤:?ip=127.0.0.1;ls;可以看见分号没有被过滤,看到了flag.php和index.php两个文件,先尝试能不能打开flag.php:?ip=127.0.0.1;catflag.php;能看出空格被过滤了,我们用$IFS$1绕过空格:?ip=127.0.0.1;cat$IFS$1flag.php;可以看见flag也被过滤了,我们打开i......
  • CTF笔记——[GXYCTF2019]禁止套娃 1
    [GXYCTF2019]禁止套娃1打开题目之后什么都没看到所以进行常规的检测漏洞,扫描目录发现存在.git文件夹下的文件存在#DirsearchstartedSunMar1015:19:392024as:D:\Python\Scripts\dirsearch-uhttp://849b4a98-3df3-4abb-927e-1a358a178e30.node5.buuoj.cn:81/-x429......
  • 文件上传例题:[GXYCTF2019]BabyUpload
    文件上传例题:[GXYCTF2019]BabyUpload打开网址明显文件上传上传简单php马尝试后缀名过滤,使用BP抓包进行修改提示文件类型不对,修改成image/jpeg提示还是php,那换成js马<scriptlanguage="php">eval($_POST['cmd']);</script>上传成功解析php代码需要.htaccess文件在文......
  • [GXYCTF2019]禁止套娃
    [GXYCTF2019]禁止套娃打开环境没有发现什么提示,使用dirsearch扫描目录,发现git泄露。通过githack下载源码<?phpinclude"flag.php";echo"flag在哪里呢?<br>";if(isset($_GET['exp'])){if(!preg_match('/data:\/\/|filter:\/\/|php:\/\/|phar:\......
  • [GXYCTF2019]BabySQli
    [GXYCTF2019]BabySQli打开是一个登录页面任意输入账号密码提示wronguser输入admin提示wrongpass,说明有admin的账号并且在页面源代码中发现一串经过编码后的字符串经过base32和base64解码后得到SQL语句使用万能密码进行尝试,得到donothackme!的结果根据源码提示,我......