2023极客大挑战WP
WEEK1
SignIn
题目描述:
Bibo...Hello! 你好! こんにちは! Привет! 5359437b48656c6c6f5f576f726c645f43727970746f5f6269626f6269626f7d… Hmm... Something goes wrong with my grettings bot.
做题流程:
hex解码
proof_of_work
题目描述:
题目链接:nc 59.110.20.54:5526 Build your own function to solve proof_of_work!
做题流程:
爆破sha256
exp:
from string import *
from hashlib import *
from string import *
import sys
c_sha256 = '49827ac949fbba5a07aa8ca286c2ec23175cd8d1f88fbe4821d7a304da3bec4b'
sh = sha1()
dict = ascii_letters + digits
print(dict)
k = []
print(ascii_letters)
for i in dict:
print(i)
for j in dict:
for k in dict:
for x in dict:
c_ascii = i + j + k + x + 'avhfc4wnKN3c6lYj'
z = sha256(c_ascii.encode()).hexdigest()
if z == c_sha256:
print(z)
print(c_ascii)
sys.exit(1)
# print(c_ascii)
SimpleRSA
题目描述:
So simple RSA! Wait... Are you kidding me? https://en.wikipedia.org/wiki/RSA_(cryptosystem)
from Crypto.Util.number import *
from gmpy2 import *
p = 24724324630507415330944861660078769085865178656494256140070836181271808964994457686409910764936630391300708451701526900994412268365698217113884698394658886249353179639767806926527103624836198494439742123128823109527320850165486500517304731554371680236789357527395416607541627295126502440202040826686102479225702795427693781581584928770373613126894936500089282093366117940069743670997994742595407158340397268147325612840109162997306902492023078425623839297511182053658542877738887677835528624045235391227122453939459585542485427063193993069301141720316104612551340923656979591045138487394366671477460626997125944456537
c = 510345661718450375632304764819724223824018609359964259503762283253350010161515190912152623604019093266967095847334388281390406831587663253164256543905694021952211220652820225527413861208452760215767828927039893435528572148282529198773772864255061213208279999011194952146362748485103032149806538140693537361755210176698895104708379400806511907719904867068865970241208806615061055047254026118016836750283966478103987375361826198930529462261013324904522014804502582865716441828895047550041401172127129749969507853355531197814919603963664646220505672302543085959372679395717892060245461464861507164276442140407308832537707450729432224150754603518526288767105682399190438680085925078051459448618725871249563011864525585870188123725554411655044152994826056900502298772802133526591794328224932405680583757307064395792317383571866619582974377344736930271554160701478385763426091091686496788999588340419226785217028504684542197970387916262126278955278523452903043316452825738030645100271595942652498852506660789605846309602343932245435421425673058238785509280366229754404949219663043627431437755087855502139890639468481922788973821783957766433857773771229298328019250652625289700950165414584983487319078090573179470893450632419467111117341472
e = 65537
d = invert(e, p - 1)
print(long_to_bytes(powmod(c, d, p)))
做题流程:
发现p有2048位,m远小于p,直接用p做rsa解密
from Crypto.Util.number import *
from gmpy2 import *
p = 24724324630507415330944861660078769085865178656494256140070836181271808964994457686409910764936630391300708451701526900994412268365698217113884698394658886249353179639767806926527103624836198494439742123128823109527320850165486500517304731554371680236789357527395416607541627295126502440202040826686102479225702795427693781581584928770373613126894936500089282093366117940069743670997994742595407158340397268147325612840109162997306902492023078425623839297511182053658542877738887677835528624045235391227122453939459585542485427063193993069301141720316104612551340923656979591045138487394366671477460626997125944456537
c = 510345661718450375632304764819724223824018609359964259503762283253350010161515190912152623604019093266967095847334388281390406831587663253164256543905694021952211220652820225527413861208452760215767828927039893435528572148282529198773772864255061213208279999011194952146362748485103032149806538140693537361755210176698895104708379400806511907719904867068865970241208806615061055047254026118016836750283966478103987375361826198930529462261013324904522014804502582865716441828895047550041401172127129749969507853355531197814919603963664646220505672302543085959372679395717892060245461464861507164276442140407308832537707450729432224150754603518526288767105682399190438680085925078051459448618725871249563011864525585870188123725554411655044152994826056900502298772802133526591794328224932405680583757307064395792317383571866619582974377344736930271554160701478385763426091091686496788999588340419226785217028504684542197970387916262126278955278523452903043316452825738030645100271595942652498852506660789605846309602343932245435421425673058238785509280366229754404949219663043627431437755087855502139890639468481922788973821783957766433857773771229298328019250652625289700950165414584983487319078090573179470893450632419467111117341472
e = 65537
d = invert(e, p - 1)
print(long_to_bytes(powmod(c, d, p)))
OTPTwice
题目描述:
I invented a new symmetric cryptosystem, and I believe you will never break it!
from pwn import xor
from os import urandom
flag = b"SYC{Al3XEI_FAKE_FLAG}"
# step0: key generation & distribution
def s0(msg):
k1,k2 = [urandom(len(msg)) for _ in "__"]
return k1,k2
#
# step1: Alice encrypt M, and send it to Bob
def s1(msg,k1):
c1 = xor(msg,k1)
return c1
# step2: Bob encrypt c1, and send it to Alice
def s2(msg,k2):
c2 = xor(msg,k2)
return c2
# step3: Alice decrypt c2, and send it to Bob.
def s3(msg,k1):
c3 = xor(msg,k1)
return c3
# step4: Bob decrypt c3, get M.
def s4(msg,k2):
m_ = xor(msg,k2)
return m_
def encrypt(msg,k1,k2):
c1 = s1(msg,k1)
c2 = s2(c1,k2)
c3 = s3(c2,k1)
m_ = s4(c3,k2)
assert msg == m_
# Here's what hacker Eve got:
def encrypt_(msg,k1,k2):
c1 = s1(msg,k1)
c2 = s2(c1,k2)
c3 = s3(c2,k1)
m_ = s4(c3,k2)
if HACK == True:
print(c1)
print(c2)
print(c3)
k1,k2 = s0(flag)
encrypt_(flag,k1,k2)
'''
b'\xdbi\xab\x8d\xfb0\xd3\xfe!\xf8Xpy\x80w\x8c\x87\xb9'
b'o\xb0%\xfb\xdb\x0e\r\x04\xde\xd1\x9a\x08w\xda4\x0f\x0cR'
b'\xe7\x80\xcd\ria\xb2\xca\x89\x1a\x9d;|#3\xf7\xbb\x96'
'''
做题流程:
通过xor即可还原key,出m
from Crypto.Util.number import *
from gmpy2 import *
c1 = bytes_to_long(b'\xdbi\xab\x8d\xfb0\xd3\xfe!\xf8Xpy\x80w\x8c\x87\xb9')
c2 = bytes_to_long(b'o\xb0%\xfb\xdb\x0e\r\x04\xde\xd1\x9a\x08w\xda4\x0f\x0cR')
c3 = bytes_to_long(b'\xe7\x80\xcd\ria\xb2\xca\x89\x1a\x9d;|#3\xf7\xbb\x96')
k1 = c2 ^ c3
k2 = c1 ^ c2
m_ = c3 ^ k2
print(long_to_bytes(m_))
OldAlgorithm
题目描述:
An old algorithm but widely used nowadays.
from Crypto.Util.number import *
import os
flag = b"SYC{Al3XEI_FAKE_FLAG}"
pad = lambda msg,padlen: msg+os.urandom(padlen-len(msg))
flag = pad(flag,32)
print(len(flag))
p = [getPrime(16) for _ in range(32)]
c = [bytes_to_long(flag)%i for i in p]
print('p=',p)
print('c=',c)
'''
p= [58657, 47093, 47963, 41213, 57653, 56923, 41809, 49639, 44417, 38639, 39857, 53609, 55621, 41729, 60497, 44647, 39703, 55117, 44111, 57131, 37747, 63419, 63703, 64007, 46349, 39241, 39313, 44909, 40763, 46727, 34057, 56333]
c= [36086, 4005, 3350, 23179, 34246, 5145, 32490, 16348, 13001, 13628, 7742, 46317, 50824, 23718, 32995, 7640, 10590, 46897, 39245, 16633, 31488, 36547, 42136, 52782, 31929, 34747, 29026, 18748, 6634, 9700, 8126, 5197]
'''
做题流程:
发现多组c,p,一眼crt
from Crypto.Util.number import *
from gmpy2 import *
p= [58657, 47093, 47963, 41213, 57653, 56923, 41809, 49639, 44417, 38639, 39857, 53609, 55621, 41729, 60497, 44647, 39703, 55117, 44111, 57131, 37747, 63419, 63703, 64007, 46349, 39241, 39313, 44909, 40763, 46727, 34057, 56333]
c= [36086, 4005, 3350, 23179, 34246, 5145, 32490, 16348, 13001, 13628, 7742, 46317, 50824, 23718, 32995, 7640, 10590, 46897, 39245, 16633, 31488, 36547, 42136, 52782, 31929, 34747, 29026, 18748, 6634, 9700, 8126, 5197]
func = crt(c, p)
print(long_to_bytes(func))
easy_classic
题目描述:
非常好套娃,使我的古典旋转
做题流程:
好玩,爱玩
第一层:凯撒
第二层:栅栏
第三层:base64
第四层:与熊论禅
第五层:key为base100,加密为playfair
SYC{classical_1s_fun}
WEEK2
PolyRSA
题目描述:
Harder RSA. Check it out!
import gmpy2
from Crypto.Util.number import *
flag = b"SYC{Al3XEI_FAKE_FLAG}"
p,q = [getPrime(2048) for _ in "__"]
e1,e2 = [getPrime(17) for _ in "__"]
e = 65537
n = p*q
c1 = gmpy2.powmod(2*p + 3*q,e1,n)
c2 = gmpy2.powmod(5*p + 7*q,e2,n)
c = gmpy2.powmod(bytes_to_long(flag),e,n)
print("e1=",e1)
print("e2=",e2)
print("c1=",c1)
print("c2=",c2)
print("c=",c)
print("n=",n)
#e1= 113717
#e2= 80737
#c1= 97528398828294138945371018405777243725957112272614466238005409057342884425132214761228537249844134865481148636534134025535106624840957740753950100180978607132333109806554009969378392835952544552269685553539656827070349532458156758965322477969141073720173165958341043159560928836304172136610929023123638981560836183245954461041167802574206323129671965436040047358250847178930436773249800969192016749684095882580749559014647942135761757750292281205876241566597813517452803933496218995755905344070203047797893640399372627351254542342772576533524820435965479881620338366838326652599102311019884528903481310690767832417584600334987458835108576322111553947045733143836419313427495888019352323209000292825566986863770366023326755116931788018138432898323148059980463407567431417724940484236335082696026821105627826117901730695680967455710434307270501190258033004471156993017301443803372029004817834317756597444195146024630164820841200575179112295902020141040090350486764038633257871003899386340004440642516190842086462237559715130631205046041819931656962904630367121414263911179041905140516402771368603623318492074423223885367923228718341206283572152570049573607906130786276734660847733952210105659707746969830132429975090175091281363770357
#c2= 353128571201645377052005694809874806643786163076931670184196149901625274899734977100920488129375537186771931435883114557320913415191396857882995726660784707377672210953334914418470453787964899846194872721616628198368241044602144880543115393715025896206210152190007408112767478800650578941849344868081146624444817544806046188600685873402369145450593575618922226415069043442295774369567389939040265656574664538667552522329712111984168798829635080641332045614585247317991581514218486004191829362787750803153463482021229058714990823658655863245025037102127138472397462755776598314247771125981017814912049441827643898478473451005083533693951329544115861795587564408860828213753948427321483082041546722974666875065831843384005041800692983406353922680299538080900818930589336142421748023025830846906503542594380663429947801329079870530727382679634952272644949425079242992486832995962516376820051495641486546631849426876810933393153871774796182078367277299340503872124124714036499367887886486264658590613431293656417255355575602576047502506125375605713228912611320198066713358654181533335650785578352716562937038768171269136647529849805172492594142026261051266577821582011917001752590659862613307646536049830151262848916867223615064832279222
#c= 375617816311787295279632219241669262704366237192565344884527300748210925539528834207344757670998995567820735715933908541800125317082581328287816628816752542104514363629022246620070560324071543077301256917337165566677142545053272381990573611757629429857842709092285442319141751484248315990593292618113678910350875156232952525787082482638460259354559904243062546518553607882194808191571131590524874275187750985821420412987586148770397073003186510357920710387377990379862185266175190503647626248057084923516190642292152259727446111686043531725993433395002330208067534104745851308178560234372373476331387737629284961288204368572750848248186692623500372605736825205759172773503283282321274793846281079650686871355211691681512637459986684769598186821524093789286661348936784712071312135814683041839882338235290487868969391040389837253093468883093296547473466050960563347060307256735803099039921213839491129726807647623542881247210251994139130146519265086673883077644185971830004165931626986486648581644383717994174627681147696341976767364316172091139507445131410662391699728189797082878876950386933926807186382619331901457205957462337191923354433435013338037399565519987793880572723211669459895193009710035003369626116024630678400746946356
#n= 728002565949733279371529990942440022467681592757835980552797682116929657292509059813629423038094227544032071413317330087468458736175902373398210691802243764786251764982802000867437756347830992118278032311046807282193498960587170291978547754942295932606784354258945168927044376692224049202979158068158842475322825884209352566494900083765571037783472505580851500043517614314755340168507097558967372661966013776090657685241689631615245294004694287660685274079979318342939473469143729494106686592347327776078649315612768988028622890242005700892937828732613800620455225438339852445425046832904615827786856105112781009995862999853122308496903885748394541643702103368974605177097553007573113536089894913967154637055293769061726082740854619536748297829779639633209710676774371525146758917646731487495135734759201537358734170552231657257498090553682791418003138924472103077035355223367678622115314235119493397080290540006942708439607767313672671274857069053688258983103863067394473084183472609906612056828326916114024662795812611685559034285371151973580240723680736227737324052391721149957542711415812665358477474058103338801398214688403784213100455466705770532894531602252798634923125974783427678469124261634518543957766622712661056594132089
做题流程:
$$\left\{ \begin{array}{rcl} {c_1}^{e_2}\equiv (2p+3q)^{e_1e_2}&(mod\ n)\\ {c_2}^{e_1}\equiv (5p+7q)^{e_1e_2}&(mod\ n)\\ \end{array} \right. $$
二项式展开化简:
$$\left\{ \begin{array}{rcl} {c_1}^{e_2}\equiv (2p)^{e_1e_2}+(3q)^{e_1e_2}&(mod\ n)\\ {c_2}^{e_1}\equiv (5p)^{e_1e_2}+(7q)^{e_1e_2}&(mod\ n)\\ \end{array} \right. $$
令$\left\{ \begin{array}{rcl} a=2^{e_1e_2}&(mod\ n)\\ b=3^{e_1e_2}&(mod\ n)\\ c=5^{e_1e_2}&(mod\ n)\\ d=7^{e_1e_2}&(mod\ n)\\ \end{array} \right. $
则有:
$$\left\{ \begin{array}{rcl} {c_1}^{e_2}\equiv a*p^{e_1e_2}+b*q^{e_1e_2}\ (mod\ n)\\ {c_2}^{e_1}\equiv c*p^{e_1e_2}+d*q^{e_1e_2}\ (mod\ n)\\ \end{array} \right. $$
将$式1*d-式2*b$得
$$(ad-bc)p^{e_1e_2}\equiv d*{c_1}^{e_2}-b*{c_2}^{e_1}\ (mod n)$$
所以:
$$p^{e_1e_2}\equiv {(ad-bc)}^{-1}(d*{c_1}^{e_2}-b*{c_2}^{e_1})\ (mod n)$$
$$p=gcd(p^{e_1e_2},n)$$
接着普通rsa
Exp:
from Crypto.Util.number import *
from gmpy2 import *
e1 = 113717
e2 = 80737
c1 = 97528398828294138945371018405777243725957112272614466238005409057342884425132214761228537249844134865481148636534134025535106624840957740753950100180978607132333109806554009969378392835952544552269685553539656827070349532458156758965322477969141073720173165958341043159560928836304172136610929023123638981560836183245954461041167802574206323129671965436040047358250847178930436773249800969192016749684095882580749559014647942135761757750292281205876241566597813517452803933496218995755905344070203047797893640399372627351254542342772576533524820435965479881620338366838326652599102311019884528903481310690767832417584600334987458835108576322111553947045733143836419313427495888019352323209000292825566986863770366023326755116931788018138432898323148059980463407567431417724940484236335082696026821105627826117901730695680967455710434307270501190258033004471156993017301443803372029004817834317756597444195146024630164820841200575179112295902020141040090350486764038633257871003899386340004440642516190842086462237559715130631205046041819931656962904630367121414263911179041905140516402771368603623318492074423223885367923228718341206283572152570049573607906130786276734660847733952210105659707746969830132429975090175091281363770357
c2 = 353128571201645377052005694809874806643786163076931670184196149901625274899734977100920488129375537186771931435883114557320913415191396857882995726660784707377672210953334914418470453787964899846194872721616628198368241044602144880543115393715025896206210152190007408112767478800650578941849344868081146624444817544806046188600685873402369145450593575618922226415069043442295774369567389939040265656574664538667552522329712111984168798829635080641332045614585247317991581514218486004191829362787750803153463482021229058714990823658655863245025037102127138472397462755776598314247771125981017814912049441827643898478473451005083533693951329544115861795587564408860828213753948427321483082041546722974666875065831843384005041800692983406353922680299538080900818930589336142421748023025830846906503542594380663429947801329079870530727382679634952272644949425079242992486832995962516376820051495641486546631849426876810933393153871774796182078367277299340503872124124714036499367887886486264658590613431293656417255355575602576047502506125375605713228912611320198066713358654181533335650785578352716562937038768171269136647529849805172492594142026261051266577821582011917001752590659862613307646536049830151262848916867223615064832279222
cc = 375617816311787295279632219241669262704366237192565344884527300748210925539528834207344757670998995567820735715933908541800125317082581328287816628816752542104514363629022246620070560324071543077301256917337165566677142545053272381990573611757629429857842709092285442319141751484248315990593292618113678910350875156232952525787082482638460259354559904243062546518553607882194808191571131590524874275187750985821420412987586148770397073003186510357920710387377990379862185266175190503647626248057084923516190642292152259727446111686043531725993433395002330208067534104745851308178560234372373476331387737629284961288204368572750848248186692623500372605736825205759172773503283282321274793846281079650686871355211691681512637459986684769598186821524093789286661348936784712071312135814683041839882338235290487868969391040389837253093468883093296547473466050960563347060307256735803099039921213839491129726807647623542881247210251994139130146519265086673883077644185971830004165931626986486648581644383717994174627681147696341976767364316172091139507445131410662391699728189797082878876950386933926807186382619331901457205957462337191923354433435013338037399565519987793880572723211669459895193009710035003369626116024630678400746946356
n = 728002565949733279371529990942440022467681592757835980552797682116929657292509059813629423038094227544032071413317330087468458736175902373398210691802243764786251764982802000867437756347830992118278032311046807282193498960587170291978547754942295932606784354258945168927044376692224049202979158068158842475322825884209352566494900083765571037783472505580851500043517614314755340168507097558967372661966013776090657685241689631615245294004694287660685274079979318342939473469143729494106686592347327776078649315612768988028622890242005700892937828732613800620455225438339852445425046832904615827786856105112781009995862999853122308496903885748394541643702103368974605177097553007573113536089894913967154637055293769061726082740854619536748297829779639633209710676774371525146758917646731487495135734759201537358734170552231657257498090553682791418003138924472103077035355223367678622115314235119493397080290540006942708439607767313672671274857069053688258983103863067394473084183472609906612056828326916114024662795812611685559034285371151973580240723680736227737324052391721149957542711415812665358477474058103338801398214688403784213100455466705770532894531602252798634923125974783427678469124261634518543957766622712661056594132089
e = 65537
ee = e1 * e2
a = powmod(2, ee, n)
b = powmod(3, ee, n)
c = powmod(5, ee, n)
d = powmod(7, ee, n)
t = a * d - b * c
inv_t = invert(t, n)
pp = inv_t * (d * powmod(c1, e2, n) - b * powmod(c2, e1, n)) % n
p = gcd(pp, n)
assert isPrime(p)
q = n // p
assert isPrime(q)
print(q)
phi = (p - 1) * (q - 1)
dd = invert(e, phi)
m = powmod(cc, dd, n)
print(long_to_bytes(m))
Fi1nd_th3_x'
题目描述:
听说在那个大陆有位叫jrl777的旅行者......Cryptoer穿越到了提瓦特就要拿出真本事!
做题流程:
文本不知道有什么用
一个CRT就解决了,迷惑(
考点应该是不互素情况下的CRT
Exp:
from Crypto.Util.number import *
from gmpy2 import *
p = 13014610351521460822156239705430709078128228907778181478242620569429327799535062679140131416771915929573454741755415612880788196172134695027201422226050343
q = 12772373441651008681294250861077909144300908972709561019514945881228862913558543752401850710742410181542277593157992764354184262443612041344749961361188667
r = 12128188838358065666687296689425460086282352520167544115899775800918383085863282204525519245937988837403739683061218279585168168892037039644924073220678419
dp = 116715737414908163105708802733763596338775040866822719131764691930369001776551671725363881836568414327815420649861207859100479999650414099346914809923964116101517432576562641857767638396325944526867458624878906968552835814078216316470330511385701105459053294771612727181278955929391807414985165924450505855941
dq = 44209639124029393930247375993629669338749966042856653556428540234515804939791650065905841618344611216577807325504984178760405516121845853248373571704473449826683120387747977520655432396578361308033763778324817416507993263234206797363191089863381905902638111246229641698709383653501799974217118168526572365797
dr = 60735172709413093730902464873458655487237612458970735840670987186877666190533417038325630420791294593669609785154204677845781980482700493870590706892523016041087206844082222225206703139282240453277802870868459288354322845410191061009582969848870045522383447751431300627611762289800656277924903605593069856921
c = 93063188325241977486352111369210103514669725591157371105152980481620575818945846725056329712195176948376321676112726029400835578531311113991944495646259750817465291340479809938094295621728828133981781064352306623727112813796314947081857025012662546178066873083689559924412320123824601550896063037191589471066773464829226873338699012924080583389032903142107586722373131642720522453842444615499672193051587154108368643495983197891525747653618742702589711752256009
n = p * q * r
phi = (p - 1) * (q - 1) * (r - 1)
d=crt([dp, dq, dr],[phi // (p - 1),phi // (q - 1),phi // (r - 1)])
m = powmod(c,d,n)
print(long_to_bytes(m))
Simple3DES
题目描述:
nc 59.110.20.54:23333 https://blog.csdn.net/Mr_wzc/article/details/121713518
from Crypto.Cipher import DES3
from Crypto.Util.number import *
import os
import random
import string
import hashlib
xor = lambda a,b: bytes([a[i % len(a)] ^ b[i % len(b)] for i in range(max(len(a), len(b)))])
pad = lambda msg,padlen: msg+chr((padlen-(len(msg)%padlen))).encode()*(padlen-(len(msg)%padlen))
flag = os.environ.get("FLAG", "SYC{Al3XEI_FAKE_FLAG}").encode()
sec = os.urandom(8)
banner = '|'*70
DEBUG = False
def proof_of_work():
if DEBUG:
return True
proof = ''.join([random.choice(string.ascii_letters+string.digits) for _ in range(20)])
digest = hashlib.sha256(proof.encode()).hexdigest()
print("sha256(XXXX+%s) == %s" % (proof[4:], digest))
x = input("Give me XXXX: ")
if len(x)!=4 or hashlib.sha256((x+proof[4:]).encode()).hexdigest() != digest:
return False
print("Right!")
return True
def enc(msg,key):
try:
key = long_to_bytes(key)
msg = xor(long_to_bytes(msg),sec)
des = DES3.new(key,DES3.MODE_ECB)
ct = xor(des.encrypt(pad(msg,8)),sec)
return bytes_to_long(ct)
except Exception as e:
print(e)
return Exception
def service():
cnt = 0
if not proof_of_work():
exit()
print(banner)
print('Simple DES Encryption Service')
print(banner)
while cnt<2:
print('1. Encrypt\n2. Get encrypted flag.')
choice = int(input('> '))
if choice == 1:
print('Input msg:')
msg = int(input('> ').strip())
print('Input key:')
key = int(input('> ').strip())
print(enc(msg,key))
elif choice == 2:
print('Input key:')
key = int(input('> ').strip())
print(enc(bytes_to_long(flag),key))
else:
exit()
cnt+=1
print(banner)
print('Bye!')
exit()
try:
service()
except Exception:
print("Something goes wrong...\n")
print(banner+'\n')
exit()
做题流程:
看到这个pad,想到随便传个8位,则明文和sec异或得到的就是一个8位,被被填充后成16位则最后8位都是\x08,发现经过3des后末尾八位都是固定的,我们用密钥把任意一个8位+8位\x00加密,发现末尾8位都是一串固定的数,将这个8位与输出异或即可得到sec,得到sec再逆着走边加密流程即可得到flag
Exp:
from Crypto.Util.number import *
from Crypto.Cipher import DES3
from gmpy2 import *
import random
import string
import hashlib
import os
xor = lambda a,b: bytes([a[i % len(a)] ^ b[i % len(b)] for i in range(max(len(a), len(b)))])
pad = lambda msg,padlen: msg+chr((padlen-(len(msg)%padlen))).encode()*(padlen-(len(msg)%padlen))
key = b'1234567812345677'
msg = b'\x15|\x07\x172\xfe\xc5\xe5'
print(len(msg))
sec = os.urandom(8)
print(len(sec))
des = DES3.new(key,DES3.MODE_ECB)
print(pad(sec, 8))
print(des.encrypt(pad(sec, 8)))
ct = xor(des.encrypt(pad(sec, 8)),sec)
print(len(ct))
z = (long_to_bytes(130827495204001562781583811333231577670))
print(xor(z, msg))
sec = b'\x9f\x07\xe7\x88\x17\x8fO\xa3'
print(len(sec))
z = (long_to_bytes(3635303539058369704084970711745626839589893640907549430077))
m = (xor(z, sec))
m = des.decrypt(m)
print(xor(m, sec))
JPGDiff
题目描述:
图片中的字符串即为flag
做题流程:
推256256走法,将图片弯曲成一个256256的图片(人懒,用的CryptoCTF2023的生成函数)
from PIL import Image
def sox(n, d):
x, y, t = 0, 0, d
for s in range(n - 1):
u = 1 & t // 2
v = 1 & t ^ u
x, y = spin(2**s, x, y, u, v)
x += 2**s * u
y += 2**s * v
t = t // 4
return x, y
def spin(n, x, y, u, v):
if v == 0:
if u == 1:
x = n - 1 - x
y = n - 1 - y
x, y = y, x
return x, y
def get_path_sequence(n):
path_sequence = []
for d in range(n**2):
x, y = sox(n, d)
path_sequence.append((x, y))
return path_sequence
raw = Image.open("/home/nightmare/Cryp/geek_chanllenge/ct.png")
new_image = Image.new("RGB", (256,256), "white")
images = []
for i in range(0,65536):
region = raw.crop((0,i,1,i+1))
images.append(region)
path = []
path = get_path_sequence(256)
for i in range(len(path)):
new_image.paste(images[i],(path[i][0],path[i][1]))
new_image.save("/home/nightmare/Cryp/geek_chanllenge/out.png")
翻转一下,得到图片
Energetic_Carcano
题目描述:
nc 59.110.20.54:8763 https://en.wikipedia.org/wiki/Elliptic-curve_cryptography
# from sage.all import *
import os
import random
import string
import hashlib
from Crypto.Util.number import *
DEBUG = True
banner = '|'*70
flag = os.environ.get("FLAG", b"SYC{Al3XEI_FAKE_FLAG}").encode()
pbits = 120
abp = "abp"
def proof_of_work():
if DEBUG:
return True
proof = ''.join([random.choice(string.ascii_letters+string.digits) for _ in range(20)])
digest = hashlib.sha256(proof.encode()).hexdigest()
print("sha256(XXXX+%s) == %s" % (proof[4:], digest))
x = input("Give me XXXX: ")
if len(x)!=4 or hashlib.sha256((x+proof[4:]).encode()).hexdigest() != digest:
return False
print("Right!")
return True
def check(a,b,p,turn,ans):
if DEBUG:
return True
try:
if turn == "a":
return int(a) == ans
if turn == "b":
return int(b) == ans
if turn == "p":
return int(p) == ans
except Exception:
exit()
try:
if not proof_of_work():
exit()
print(banner)
print('\nHi Crypto-ers! AL3XEI here. I know you are excellent at math, so I prepared a game for u.')
print('In the equation y^2 = x^3+ a*x + b (mod p), 4 points are given. Plz give me the right a, b or p to contine the game.')
print('Good Luck!\n')
print(banner+'\n')
for i in range(10):
turn = random.choice(abp)
p = getPrime(pbits)
a,b = [next_prime(random.randint(2,p)) for _ in "ab"]
curve = EllipticCurve(GF(p),[a,b])
pts = [curve.random_point() for _ in range(4)]
pts = [(_[0], _[1]) for _ in pts]
for _ in pts:
print(_,end=" ")
print('\nGive me '+turn+" :")
ans = int(input('> '))
if check(a,b,p,turn,ans):
print("Good! Next challenge->\n")
print(banner+'\n')
pbits+=5
continue
else:
print("Something goes wrong...\n")
print(banner+'\n')
exit()
print('Congrats! Your flag is:',flag)
except Exception:
print("Something goes wrong...\n")
print(banner+'\n')
exit()
做题流程:
有原式子:
$$y^2=x^3+ax+b\ (mod p)$$
知道四个点,x和y已知
$$ \left\{\begin{array}{rcl}{y_1}^2-{x_1}^3=ax_1+b\ (mod\ p) \\ {y_2}^2-{x_2}^3= ax_2+b\ (mod\ p)\\ {y_3}^2-{x_3}^3= ax_3+b\ (mod\ p)\\ {y_4}^2-{x_4}^3= ax_4+b\ (mod\ p)\\ \end{array} \right. $$ 式2-式1和式3-式1联立得 $$\left\{ \begin{array}{rcl} ({y_2}^2-{x_2}^3)-({y_1}^2-{x_1}^3)= ax_2-ax_1\ (mod\ p)\\ ({y_3}^2-{x_3}^3)-({y_1}^2-{x_1}^3)= ax_3-ax_1\ (mod\ p)\\ \end{array} \right. $$ 令 $({y_2}^2-{x_2}^3)-({y_1}^2-{x_1}^3)=t_1$ , $({y_3}^2-{x_3}^3)-({y_1}^2-{x_1}^3)=t_2$ 则有: $$\left\{\begin{array}{rcl}t_1=a(x_2-x_1)(mod p)\\ t_2=a(x_3-x_1) (mod p)\\ \end{array}\right. $$
将式5 $(x_3-x_1)$,式6 $(x_2-x_1)$,相减可得到:
$$t_1*(x_3-x_1)-t_2(x_2-x_1)=0\ (mod p)$$
这样我们即可求出kp,分解后得到p,根据式5求出a,再根据原式求出b
Exp:
from Crypto.Util.number import *
from functools import reduce
from gmpy2 import *
pts = [[9919887393477746178534175105516135467884408832173, 19958266120603700511875407508208280666242793356852],[3595522573583061314509664626455857557236490082950, 7844818469778389188067619619555050311084508661624],[19012115773786761225750188806634440613045262597955, 33081986637027085345095605616372809095234468671967],[34196017632168655637054726684559122319589088633467, 33150136169196868045901637529474922917121632432058]]
xx = []
yy = []
for pt in pts:
xx.append(pt[0] ** 3)
yy.append(pt[1] ** 2)
f = []
for x in range(len(pts)):
f.append(yy[x] - yy[0] - (xx[x] - xx[0]))
# print(f)
p = f[1] * (pts[2][0] - pts[0][0]) - f[2] * (pts[1][0] - pts[0][0])
p1 = f[3] * (pts[2][0] - pts[0][0]) - f[2] * (pts[3][0] - pts[0][0])
print(gcd(p,p1))
p = 35926127419138943502466980597080965242987634950823
print(p.bit_length())
assert isPrime(p)
inv = invert(pts[1][0] - pts[0][0], p)
a = (f[1] * inv) % p
print(a)
b = (yy[1] - xx[1] - a * pts[1][0]) % p
print(b)
Just need One
题目描述:
题目链接:nc 59.110.20.54:2613 One bullet to kill all Outlaws.
import os
import random
import string
import hashlib
flag = os.environ.get("FLAG", b"SYC{Al3XEI_FAKE_FLAG}")
DEBUG = False
banner = '|'*70
if DEBUG:
print("==DEBUG MODE==")
def proof_of_work():
if DEBUG:
return True
proof = ''.join([random.choice(string.ascii_letters+string.digits) for _ in range(20)])
digest = hashlib.sha256(proof.encode()).hexdigest()
print("sha256(XXXX+%s) == %s" % (proof[4:], digest))
x = input("Give me XXXX: ")
if len(x)!=4 or hashlib.sha256((x+proof[4:]).encode()).hexdigest() != digest:
return False
print("Right!")
return True
try:
if not proof_of_work():
exit()
print(banner)
parms = [random.getrandbits(32) for _ in range(128)]
res = res = int(input('Give me x calculating f(x) :\n> '))
if res >= 2**32:
print("Give me something smaller.\n")
print(banner+'\n')
exit()
cnt = 0
for _ in range(128):
cnt += pow(res,_)*parms[_]
print(cnt)
ans = input('Give me Coefficients :\n> ')
ans = [int(_) for _ in ans.split(",")]
if ans == parms:
print('Congrats! Your flag is:',flag)
else:
exit()
except Exception:
print("Something goes wrong...\n")
print(banner+'\n')
exit()
做题流程:
每一个随机数有32位,正常只需要x取2^32就能够使得每组系数互不干扰,组成一个$$\overline{a_0a_1a_2...a_n}$$的二进制数,但题目限制了。我们可以想到x传-2^32,将得到的结果取绝对值,效果是类似的,只是每个的奇次幂的最低位会少1,偶次幂的数要用2^32减去,这样我们就可以得到全部系数
由于懒得写交互,所以。。。
exp:
st = 2 ** 32
print(st)
f = 175110518470050214311252208588439497233859974965843301573501150665105370885160932732266664106894635769347686910638085239904480094492658846059636249060430246503662967313895029621524454404153167719468689989026081151299490589243124365354471312558228639710222850879091900838412736214856057475205489122589865518469465813833850258524613215593668851547025232903349052899457691500393609804421428126021357281586324058308332941103714584366378427332509333316091374742966486591321245048957767182630317606854985994814985728860404082674626469535091912244027690957063979237769162558978220671124629145227531716385828491939130328762969373260692120133304770046361957730804573737550194784956854802153210176261676477520184939283281851793173711909264376089655413313757049962215085196884638283727053130393809491633549317643797654799739907743650478878803810420222850065785495908199760719703304402447147992885462581136660381797268526563537319402991265099090205951380228863538262567329997046302680663223606385029584869529614437282799927770669536355795512010240094506162690330618811758684527784885432204861343484107321006464765901128403864624500882456479620901930927911105148561126202224552724777210945131303939541175114958582099164318448840447020045997403836
f = bin(f)
print(f)
s = str(f).replace('0b','00')
chunk_size = 64
chunks = [s[i:i + chunk_size] for i in range(0, len(s), chunk_size)]
a_list = []
for chunk in reversed(chunks):
c1 = chunk[:32]
c2 = chunk[32:]
t1 = int(c1, 2) + 1
t2 = st - int(c2, 2)
a_list.append(str(t2))
a_list.append(str(t1))
print(",".join(a_list))
WEEK3
Diligent_Liszt
题目描述:
https://en.wikipedia.org/wiki/Discrete_logarithm
做题流程:
一眼p,q,r光滑,Pohlig–Hellman直接嗦(la佬脚本真好用)
def babystep_giantstep(g, y, p, q=None):
if q is None:
q = p - 1
m = int(q**0.5 + 0.5)
# Baby step
table = {}
gr = 1 # g^r
for r in range(m):
table[gr] = r
gr = (gr * g) % p
# Giant step
try:
gm = pow(g, -m, p) # gm = g^{-m}
except:
return None
ygqm = y # ygqm = y * g^{-qm}
for q in range(m):
if ygqm in table:
return q * m + table[ygqm]
ygqm = (ygqm * gm) % p
return None
# Pohlig–Hellman法
def pohlig_hellman_DLP(g, y, p):
crt_moduli = []
crt_remain = []
for q, _ in factor(p-1):
x = babystep_giantstep(pow(g,(p-1)//q,p), pow(y,(p-1)//q,p), p, q)
if (x is None) or (x <= 1):
continue
crt_moduli.append(q)
crt_remain.append(x)
x = crt(crt_remain, crt_moduli)
return x
g = 3
y = 5385116324746699759660077007129548063211490907227715474654765255668507958312745677683558789874078477569613259930365612562164095274660123330458355653249805062678976259429733060364358954180439218947514191603330532117142653558803034110759332447742304749985874760435453594107494324797235909651178472904825071375135846093354526936559640383917210702874692725723836865724807664892994298377375580807917514349966834376413176898806591411038129330967050554114677719107335006266
p = 1068910928091265978478887270179608140018534288604159452828300604294675735481804963679672853224192480667904101881092533866322948043654533322038484907159945421
x = pohlig_hellman_DLP(g, y, p)
print(long_to_bytes(x))
# print(pow(g, x, p) == y)
Quick_Robert
题目描述:
nc 59.110.20.54:3042 https://en.wikipedia.org/wiki/Quadratic_residue
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Hi Crypto-ers! AL3XEI Here. In number theory, if there exists an integer q satisfying x^2=q(mod n), q is so called a quadratic residue.
We write this calculation as L(a,p), which its value shows a is or is not quadratic residue modulo p.
Below, you need to give me the answer of the sum of L(a*l**2+b*l+1,p), where a,b are integers, p is a prime, and l rise from 0 to p-1.
For example, given a = 2, b = 3, c = 1, p = 5, the answer will be
L(1, 5) + L(6, 5) + L(15, 5) + L(28, 5) + L(45, 5) = 1.
Hope you success!
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
做题流程:
更新前:
经过测试发现给的a,b,p满足a是二次剩余
$$a=t^2$$
所以满足完全平方式:
$$ax^2+bx+1=(tx+1)^2\ (mod\ p)$$
所以按理来说,题目答案应该都为0
题目有些小问题,传入答案和算出来不相符,这题全部传p-1即出
更新后:
$$ \begin{equation} L(a,p)=\left\{ \begin{aligned} 0 \quad a是模p下的某个因子\\ 1 \quad a是模p下的二次剩余\\ -1 \quad a是模p下二次非剩余\\ \end{aligned} \right . \end{equation} $$
会发现,L函数的求和结果仅与a是否是模p下的二次剩余有关。如果a是模p下的二次剩余,求和结果为-1;否则为1。以及更新前的那一种情况。
card_game
题目描述:
AL3XEI送给了你这个游戏的关键数据,你能预测接下来要出的牌吗 nc 59.110.20.54 4953
from Crypto.Util.number import *
from cards import Heart, Spade, Club, Diamond
from secret import flag
def choose_card(num):
x = (num>>5)%4
if x == 0:
return (Heart[(num>>6)%13]), 'Heart'
if x%4 == 1:
return (Spade[(num>>6)%13]), 'Spade'
if x%4 == 2:
return (Diamond[(num>>6)%13]), 'Diamond'
else:
return (Club[(num>>6)%13]), 'Club'
def GAME():
banner = '''
#### ## ##### ##### #### ## # # ######
# # # # # # # # # # # # ## ## #
# # # # # # # # # # # ## # #####
# ###### ##### # # # ### ###### # # #
# # # # # # # # # # # # # # #
#### # # # # ##### #### # # # # ######
'''
print(banner)
meum = '''option:
1: start game
2: get hint
3: exit
'''
print(meum)
while True:
print('input your option: ', end='')
your_input = input()
if your_input == '1':
n = getPrime(36)
m = getPrime(16)
c = getPrime(16)
seed = getPrime(36)
out = seed
round = 0
score = 0
res = []
while True:
round += 1
res = []
print(f'round:{round}')
print(f'score:{score}')
for i in range (3):
out = (out*m+c)%n
res.append(out)
if round == 1:
for i in res:
card, suit = choose_card(i)
print(card)
elif round==2 or round==3: #gift
for i in res:
card, suit = choose_card(i)
print(card)
print(f'gift: {res}')
else:
cards = []
suits = []
for i in range(len(res)):
card, suit = choose_card(res[i])
cards.append(card)
suits.append(suit)
print("Give me your guess: (example: Heart_1 Club_2 Diamond_3)")
try:
g_1, g_2, g_3 = input().split()
g_1, g_2, g_3 = g_1.split('_'), g_2.split('_'), g_3.split('_')
except ValueError:
print("Please enter in the correct format.")
return
if (g_1[0] == suits[0] and g_1[1] == cards[0][15]) and (g_2[0] == suits[1] and g_2[1] == cards[1][15]) and (g_3[0] == suits[2] and g_3[1] == cards[2][15]):
for i in cards:
print(i)
print("Congratulations! You matched the cards!")
score += 1
else:
for i in cards:
print(i)
print("Try again!")
if score == 50:
print('The flag is your reward!')
print(flag)
return
else:
continue
if your_input == '2':
print("Have you ever heard of LCG?")
if your_input == '3':
break
if __name__ == '__main__':
GAME()
做题流程:
简单的lcg(靶机似乎检查不出10,所以就跑了100组找flag)
exp:
from pwn import *
from Crypto.Util.number import *
from gmpy2 import *
io = remote("59.110.20.54", 4953)
io.recv()
io.sendline(str(1).encode())
io.recvuntil(b'gift: ')
t = io.recvuntil(b']').decode().strip()
t = t[1:len(t) - 1]
x_list = t.split(', ')
# print(x_list)
x = []
for i in x_list:
xx = int(i)
x.append(xx)
io.recvuntil(b'gift: ')
t = io.recvuntil(b']').decode().strip()
t = t[1:len(t) - 1]
x_list = t.split(', ')
for i in range(len(x_list)):
xx = int(x_list[i])
x.append(xx)
x6 = int(x_list[2])
print(x)
t = []
for i in range(1, len(x)):
t.append(x[i] - x[i-1])
m = 0
for i in range(1, len(t)-1):
m = GCD(t[i+1]*t[i-1] - t[i]*t[i], m)
print(m)
assert isPrime(m)
a = (x[2] - x[1]) * inverse(x[1] - x[0], m)
b = (x[1] - a*x[0]) % m
# x.append(x6)
def choose_card(num):
x = (num>>5)%4
if x == 0:
return ((num>>6)%13 + 1), 'Heart'
if x%4 == 1:
return ((num>>6)%13 + 1), 'Spade'
if x%4 == 2:
return ((num>>6)%13 + 1), 'Diamond'
else:
return ((num>>6)%13 + 1), 'Club'
out = x6
print(out)
for i in range(100):
res = []
answer = []
for j in range(3):
out = (out * a + b) % m
res.append(out)
for j in res:
card, suit = choose_card(j)
if card >= 2 and card <= 10:
ans = suit + '_' + str(card)
if card == 1:
ans = suit + '_A'
if card == 11:
ans = suit + '_J'
if card == 12:
ans = suit + '_Q'
if card == 13:
ans = suit + '_K'
answer.append(ans)
ans = (' '.join(answer)).encode()
print(ans)
x = io.recv()
if b'flag' in x:
print(x)
sleep(0.1)
io.sendline(ans)
io.interactive()
WEEK4
EzComplex
题目描述:
And u, my friend: Complex factors! (In a double sense)
#sage9.3
from Crypto.Util.number import *
flag = b'FAKE{Do_You_know_Complex_numbers}'
p = random_prime(1 << 384)
q = random_prime(1 << 384)
n = p * q
e = 0x10001
N = pow(p, 2) + pow(q, 2)
m = bytes_to_long(flag)
c = pow(m,e,n)
print(c)
print(N)
'''
122977267154486898127643454001467185956864368276013342450998567212966113302012584153291519651365278888605594000436279106907163024162771486315220072170917153855370362692990814276908399943293854077912175867886513964032241638851526276
973990451943921675425625260267293227445098713194663380695161260771362036776671793195525239267004528550439258233703798932349677698127549891815995206853756301593324349871567926792912475619794804691721625860861059975526781239293017498
'''
做题流程:
题目给了$$p^2+q^2$$,发现这式子在复数域内可分解为$$(p+qi)(p-qi)$$于是我们可以将给出的数在复数域分解,得到p和q
exp:
from Crypto.Util.number import *
from gmpy2 import *
# N = 973990451943921675425625260267293227445098713194663380695161260771362036776671793195525239267004528550439258233703798932349677698127549891815995206853756301593324349871567926792912475619794804691721625860861059975526781239293017498
# f = ZZ[i](N)
# for i in divisors(f):
# if (i[0] ** 2 + i[1] ** 2 == N):
# p = abs(int(i[0]))
# q = abs(int(i[1]))
# if isPrime(p) and isPrime(q):
# n = i[0] * i[1]
# print(p)
# print(q)
# print(n)
p = 29962125885196559918101088622575501736433575381042696980660846307183241725227137854663856022170515177120773072848343
q = 8732781022306464325787401448517171026218291389436971731700810979177651389459896422549428444142746055523338740248707
n = p * q
e = 0x10001
c = 122977267154486898127643454001467185956864368276013342450998567212966113302012584153291519651365278888605594000436279106907163024162771486315220072170917153855370362692990814276908399943293854077912175867886513964032241638851526276
phi = (p - 1) * (q - 1)
d = invert(e, phi)
m = powmod(c, d, n)
print(long_to_bytes(m))
ext^7gcd
题目描述:
题目链接:nc 59.110.20.54:1789 (下sagemath! 不下的统统发配到安东星当嘿奴!)
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Hi Crypto-ers! AL3XEI here. Solving extended gcd over 2 primes can be easy, but what about 7 primes?
primes : [938770989594038574883307091377, 731124780451059048515699872973, 705906522337130351303390881793, 1259253321424214851154594220511, 638192849150199238389371476021, 1160157641563492827848830377527, 1225294646722407790694425867847] ( 100 bits )
Give me a0,...a5,a6:
做题流程:
题目大概意思是让$$\sum_{i=1}^7 a[i]p[i]$$的和为1,我们直接用两数做exgcd,让后面的和为0即可
exp:
p = [5902710342749394849998943371028129845573814056445154853443, 4636015201465011031253453796366492861048284694454948943011, 4002400072383962140402233513848277026571627310391097106009, 5300996721183835725509763065691627002815254108296157953417, 6076354674723684660152317912448324904347788150826788336229, 4066402285311826559568946174406730844378217729090270993737, 4206730190819808557122468467946725462023809374891116910767]
a = [0] * 7
u, d, v = xgcd(p[0], p[1])
a[0] = d
a[1] = v
for i in range(2,len(p) - 1):
a[i + 1] += p[i]
a[i] -= p[i + 1]
t = 0
for i in range(len(p)):
t += a[i] * p[i]
print(t)
ans = ''
for i in a:
ans = ans + str(i) +','
print(ans)
Algebra (复现)
题目描述:
Recently jrl888 has learned something about groebner_basis.But could U plz help him to sovle his linear algebra homework?
#utf-8
#sage
import os
from Crypto.Util.number import *
from Crypto.Util.Padding import pad
from secret import flag,e
from functools import reduce
assert reduce(lambda x,y:x&y,[i^3 - 10*i^2 + 31*i - 30==0 for i in e])
LEN = 32
flag = pad(flag,36)
def LongArray(t:list):
return [bytes_to_long(t[i]) for i in range(len(t))]
def BytesArray(t:list):
return [long_to_bytes(t[i]) for i in range(len(t))]
def xor(a, b):
return bytes([a[i%len(a)] ^^ b[i%len(b)] for i in range(max(len(a), len(b)))])
def ArrayXor(a:list,b:bytes):
return [xor(a[i],b) for i in range(len(a))]
def scissors(flag:bytes):
return [flag[i:i+len(flag)//3] for i in range(0, len(flag), len(flag)//3)]
def challenge(m: bytes, bits: int, level: int):
p = getPrime(bits)
M = random_matrix(Zmod(p), LEN).matrix_from_rows_and_columns(range(LEN), range(LEN-level))
c = vector(GF(p), m) * M
return {"p": p, "M": M.list(), "c": c.list()}
def groebner_challenge(m,e):
p = getPrime(1024)
s = sum(m)
c = [pow(m[i],e[i],p) for i in range(3)]
c.insert(0,s)
c.insert(0,p)
return c
key = os.urandom(LEN)
Get_key = challenge(key,256,0x10)
S_bytes = scissors(flag)
C_bytes = ArrayXor(S_bytes,key)
C_long = LongArray(C_bytes)
groebner_challenge = groebner_challenge(C_long,e)
with open('keyTask.chall', 'w') as f:
f.write(f"{Get_key}")
with open('groebnerTask.chall','w') as f:
f.write(f"{groebner_challenge}")
做题流程:
题目可以分为两部分,第一部分为解challenge函数获得key,第二部分则为解gorebner_challenge函数得到c_long,然后将两者xor即可
第一部分:
key对应的m向量是按字节拆分的,所以都是小量,可以通过构造格来规约出key
$m=(k_1,k_2,...,k_{32})$
$$ M=\left(\begin{matrix} M_{1,1}&M_{1,2}&...&M_{1,16}\\ M_{2,1}&M_{2,2}&...&M_{2,16}\\ &&...\\ M_{31,1}&M_{31,2}&...&M_{31,16}\\ M_{32,1}&M_{32,2}&...&M_{32,16} \end{matrix}\right) $$
$m*M=c\ (mod\ p)$
$M$和$c$都是已知量,我们要得到$m$,我们想要构造出格,首先得需要将这条等式抽取出线性方程出来
我们可以得到(总共16条):
$M_{1,i}*k_1+M_{2,i}*k_2+...+M_{31,i}*k_{31}+M_{32,i}*k_{32}=c_i\ (mod\ p)$
我们可以构造出这么一个格(在其他师傅的帮助下)
$$ L=\left(\begin{matrix} M_{1,1}&M_{1,2}&...&M_{1,16}&1&0&...&0&0\\ M_{2,1}&M_{2,2}&...&M_{2,16}&0&1&...&0&0\\ &&...\\ M_{31,1}&M_{31,2}&...&M_{31,16}&0&0&...&1&0\\ M_{32,1}&M_{32,2}&...&M_{32,16}&0&0&...&0&1\\ p&0&...&0&0&0&...&0&0\\ 0&p&...&0&0&0&...&0&0\\ &&...\\ 0&0&...&p&0&0&...&0&0\\ c_1&c_2&...&c_{32}&0&0&...&0&0 \end{matrix}\right) $$
满足:
$(k_1,k_2,...,k_{32},k_{1mod},k_{2mod},...k_{16mod},-1)L=(0,0,...,0,k_1,k_2,...,k_{32})$
所以我们就可以得到key
第二部分:
首先需要求得e,e的约束条件为:${e_i}^3-10*{e_i}^2+31*{e_i}-30=0$
我们可以用roots函数直接解就可以解出e的值
$e=[2,3,5]$
groebner_challenge即为:
$$ {m_0}^{e_0}\equiv c_0\ (mod\ p)\\ {m_1}^{e_1}\equiv c_1\ (mod\ p)\\ {m_2}^{e_2}\equiv c_2\ (mod\ p)\\ s=m_1+m_2+m_3 $$
所以我们可以根据groebner将$m_0,m_1,m_2$求出
然后将得到的m与key异或即可得到flag
exp:
from Crypto.Util.number import *
def BytesArray(t:list):
return [long_to_bytes(t[i]) for i in range(len(t))]
def xor(a, b):
return bytes([a[i%len(a)] ^^ b[i%len(b)] for i in range(max(len(a), len(b)))])
def ArrayXor(a:list,b:bytes):
return [xor(a[i],b) for i in range(len(a))]
p = 76231309481023608274751321361920497941621991893430257210800219032855778863403
m = [16697564195803960524955618666471317999653475911677692593955332155554421639339, 24805565422829448264880670396335760401288936419812226622903667065319545007990, 30402002570955975554182190550978255206265920770702396357369433463733972557272, 18233447181850080393551606050467637029754113002670714480589747787334593064733, 592902654848011644470609316176765466448791324270572419003746985532591397159, 38141098394328701291718984482265005575605052524114181112646883764482370463339, 19538035520885458475321686600845898258764219979337957736187681124215270558985, 20238271906530455379759697476409410947082642723781332031138364999846953950236, 68589425835163943859976893853743850381901810189392551426919445548155584771402, 69125498641336015332539393144100425718253100049458707350849969745083544909112, 13083949682120928694566559154939525096970647194043481405708057328879273858093, 23203059113121714797053512829874540997525934591781746540284169378085299649376, 22946531388117317614240915936458387347604741596963582908127101794515625023753, 55979468873975052067342467012297454154725653733173077039679834697623008679331, 30639339327762413454972420838209328855396759486202041356245020097084204753692, 72148374844384373140537647811727349763363643424440303708852930034097897492230, 70510577909447876165042155961990008987054640378802283966455273008397938569580, 7816397571019557637378232515822996961951657038149768517938709736489000871357, 71385034180207364002198196251789729137138388141957414602914243475029669555970, 23879618498527644070533133010929524881849183976915843192427726963620597127184, 17735043770749200859447594711305199064407694651519169622831117483831984480389, 23976962869545273044554865578229826802425540170337686767966000016386989130328, 4813526999083764015441613591159575786598306005687621653546973702651642297987, 35706013043056210868734160987149285571667410945166974218110532901324694790051, 61287332127924004349826780222152798665251527987557191801341744495498699149681, 59806212087395698267045456744835084402906230530501342953461649545673934834285, 66657482821382875051224147598709239153115890794174921121727576548156129458938, 69377007797894976274149732824887445461573605559150837203792733121879383465089, 1737071528731565332746911257107778493680445360545221708263762514076835879060, 26379023925512924142330791649751372084816373260080785068747794883981639940564, 39720534772339542897383195711251081371637848641782146840418654967747820062275, 31820568864325484588454986704171504530172236531705504762063219235205599726436, 11412415614112198143545742456902967000465243935062267743559791535435529553163, 32772401021478158811568824426072680656457459212208695033707655574301149228189, 36613809529642944778053478223817784061231181494093237801141665942724705342255, 28439197371291309320639184774010673215730459728641992931504270331352037006301, 49994376135260323921300737379653415875790622538378466317921425504902713119203, 52981071203712051253827242322882615499169952108221727146381229246217507758656, 5368198640133799911534404960909130528742165283715085781170378320545249444728, 71257635543006090454988064080839484336932780804977796104506518470528524267977, 49939544868670555386879967918014313156769501676987773456158169289120020853127, 5513849182743515680002710310848843523475129560643091243794997576549106529466, 30311080181622378163675117234336217803120444223514680794613361255903563546728, 47253144424515535707960287619419823112290982665649838216591721966391572553422, 16575095774038994598908811620087695957027774942428306451930642072988256096088, 47172637987883100907600422604046275130022245811783645092074076667564229591509, 53713237639725683804264174932950491311170902993545808552164800199466276547267, 49487719557414168923381121834394720035219644265706614752390389709105440461013, 25748413371892143171911671353160744041253936659875378210032853927568421372570, 18008028845121322299690631964537137436508497132161626102200990344058453799889, 16865923878308840204551239186825547977455975788266115306396389734737296847085, 19731302167241507517327528775906606230203827145542596977849114707067863875306, 40024901439773791188244711248598957442287420749738843516966316385631890601402, 62075661595095737466614940938346709962838454659631028910757881824583540487566, 20288133589575545550261734425136279824898448287826254319546558610232798725973, 18396337599190064130575563735025697756345644312687861801231441717383177428297, 61662649332383590957920197518379762321289652000599447145306018866100644631766, 47297278799506827936460165998522491497020441120637980131964545819062452000973, 2434481804300022098577582940503850118123308379606916558865314346784339559741, 61460717710239239905767696511877571142159463848530251055586626280454830469072, 38218092905624483835554011371470317993625264372465695584358397202189822877524, 3809308445935104222618133270413897838642480016918582790324761590850768301189, 60169484708414410769331696939509588791672824220639550859073548144342970942988, 15271709649738561680228696342185966023088016417410635809886804641185459695129, 66155017267527705428216922418146119778993818507134962459291676926961980199387, 40582325144361815094579454299209449255300583137755409783698034905476467214705, 7194805288765133581009538431376085998358337085730757398024738539141630962571, 51248452708770457503524460344461222094049441723589286717211964782544227354571, 22498197147885926650572737244750672660840424112765335329871216585556016078622, 19260029934620867188413402870565199213401541118545012025905327078018757276590, 72765401981342793804926955474372068906021406824027837530797739114362593491810, 26557733709775965549141892813261411879509070986449185646889308782249756249916, 75882964734763534706470590708116855183211267542251854842893942812696713968262, 65558131748560689919247533082377923318035739956508689196452998649978595186348, 67829993253688380288988780892768011398698114976114299036143341260518905341737, 16951826980977800861862157989815519885040882739074799726885358140199464697314, 32446755357113992870476957889986702460677003223490414366121640836329037752178, 12249592801055447145409227586142616644156448960361415580962075899504462831768, 67754539010843962660507454221523396504435027352823732054707137518864699178042, 70297827395682032833886772783589786140334218212649181539008979052239234639121, 54916877002052785044471094178468452023757703561016947516347687003813589699916, 69878767045339462957533288607625091900151500688613054221901486304429504671185, 66676699190226984651524622074479431262031540827948817625722859822091518488776, 37343359862502607786043285225073441136188109619529666103637343139525624099037, 69617008840230800774027983202746530662060112473037948560718889791912835927617, 34023459442316105245449622177764320035562291674808673245390486237383753730372, 58836217736932714605695150144545967912160645465028878381545601614754647665960, 59222748784277372772691372984001892824676042244406474647651454241867636982425, 51291183560520843117691150179745095319132263026055872920338388401683396576465, 34161743303094177732273633757443540558673772088482702756673380560373237718795, 34307131145857277718970084816120044947475446756190646647128645192254530721466, 40619186027026335519058147342009392171397856667529112161579765965818461803556, 38969816660406704957262595675482436498421224818936997122425666698567944719644, 40794121792346281796042418182247410063476511606792164833602224462315579047113, 42873094892829318419396887766229282312457081646096347608094509056075735751292, 59931536990963806751890878460380001382300908207154685797724146604005535427389, 26755875060247483082325535695838083770840387919703205792533687755344379394946, 43367143477175416179546646554235024477454387951599453206015050420503396068459, 42786261278310437859972967186896802622955631346091442879938560902191751939666, 32011605834951861381124123053237156531666295421317693417540887608617755500393, 13404880414951683157677928762115608923254793039749942268608296355486752433132, 11877089900228767684891740308804612746605973897075293419611769384342085758411, 27800240708207112469881110853080993649227712650342675861846262212114171421602, 21663581286219835659381271690002813806524703558064974946660379562231450045703, 51974697598961421376559503657823500883117393940660528716837501860648953054355, 6852742579645192782976681029352809589256614923690966236485757863903554035069, 35855739391011276573763391944486554053477241405378310460038837239370814911199, 25499317411645301621939591842312017864107631600944631297145405267790992692014, 5562131306962862994694660621066163309781065393286926932973088057349402319588, 40757942292495250026613925560811211396043227754440416656002665366852555641446, 18002370353172907998059655813638034919853029188826297237387499099629866542454, 39726689200477117673969486403738222570493365361037768374891829430070697803130, 35000135749383571988936158002043170360320337395381038811684971059559128511827, 5641310335570452388651829312936977441078446226495322610431425645339515285489, 60299748799261773479293910979569271438153013125421405725240125178140926053077, 43236034650568428166127856787899498356720414303783169784893885140891897481142, 69522811767745688129234716889716393878934461214025015629400440813257866985926, 62606640448879579972364732068956807349875925982230691648601606744009474947413, 26331285333678560461768318775460827655967933143330152424507184311854947970495, 2615412910278288709156419324276628765375142098301549535618716916032933841018, 1307892460631304569176307753782952310781666613146568927700279439753116859497, 15824651092623867390178475089970118874597630604021225496161544986644731672756, 47659224500120332057240483014529343778388581379297920665421402048441870895252, 51961864134409826142298014140833527652846234416148386918337416218362423427080, 639612686356673570435510441554421795484284145741835048078758652344450124205, 44137808563133710484189150226489053077979585402607831461142023833300560983894, 20115680634645545703803838311574504684652017307676066365011322088032653451054, 23453961374784154821574492914078706218399840238650137887046369876199717640181, 16900806176672163513368898482296275590742399269083482708344531116968904768746, 1033088239828057573934670025891372224995692390599610312154257552196539477228, 37529301212534088685439177351330248471189442148240970641467457998586018600828, 44758658558670428403704358314309089462537518462726001659629731149466886078366, 52531643561197004188179872503729166603975825497103871211472449723704365462397, 39100228068624208345956366306901887462499286634213553058495856303286399680759, 50084656888221865079923599398760080915088064018016395343407634834125281280594, 28032921509707666624060117053276138115957884170215722353372618599407776800318, 57114338186298325807231621434178101761011329483434004023292009415865817538443, 39958000825797431172033845591817417570124784702159857760068966672182242295044, 37975443995963359152259095549178743095281699999555734577840897697983385485508, 3859860826226346586118043402553604028339335048800976779370409309677283839561, 19776331828369039090338830259040913447049235836451080607341980414646928869035, 63362121603058759116851239353365138616548125502014054189583403052688368426366, 8417124938922096613738885001645171001893699423265701100265134643476256258769, 2528187862792013482327567161109437558476612366439226244624203613981198708409, 28439815484745649368170695869546901757055520618328133349460090475484778312430, 52424412563973386715004013697496582995402355069164803452768326078447171945926, 71211964764567865199498719444172950819839102789370908692811892670877437426546, 4852911497761258167355856839166668386535696525032839475042549640021600874463, 12604599543488979007038941486324219160820800119211235264504484549111970215523, 14707627286207296124221923217783940519267566530301202187069927116743690487231, 54982565303499154789362418217587368496636702638346603109876155421010038344010, 8136431912900558221508147412193693425405229437643936872474370939843895786897, 52527332407379202874730182017643715254519386368271623752276320410620277095724, 27007072982620809725787916921614997193231513388215706309009793746137114597486, 8594259875427565483767528869078604778538149152407620311805971227967328114437, 60909592616766854722440243820060988296182888536109613314378246086444257045038, 70469756657760437903499572874961531430585138343307503284848476358837249550050, 33710378649952477094787277011344679479890816598893733081269348946312192670261, 19390620159429311108580146260490873362545571928758643595249797850575767341180, 50247828125873142034313937116587841918115644881259334859484667323061010135147, 30868931184876169045518788073342820415616390474858684405301699072543537570584, 23023240981699193473119197241876724866648360970395806820123980777916962344896, 23996458076167109084834801710867359513927915053490840030842839568905219284982, 18250665434495752390574979184452774394822264315742771513276269170372150019408, 2259977738410451722290072176978139597380420312125626711897728709864167974754, 12986023697223238031523545123890690074279244756420212561751672410792825364360, 54894463714745000972296348237869203583787411196528486760265537862939294199514, 37425912176878184506602309171583658458580304531171364563977595868021237095470, 68817331576859213436304320718837111677416186125049321255877463964380611433706, 41105143390627550033327279192494325897557771670728209002015094922045099669745, 63934928583418713760166225295375893688887003690690081734249993346317611081637, 29228057983414013083385647342360130522058343918940183242873420195035620061919, 51768792160132206523829040289791168367725211511713749754357818583996335222039, 32361017699666327550854675605653538765736862329416095200206293554393607637178, 40771011482807414204888492411092965367622067483466970242712584516125501592354, 24559438367813844616191475087217959641556195075112204920097346901121612022495, 28307745491110198259585972462019261459810520986249892652055646848825309554089, 18111158553544995743378582759414760595774231715148478706446012211834819048094, 28421161206901194269925617922294395794292746509761316483882233546592347136153, 68717406158762870034008809470702721739259380362818921203097329142749903889938, 15229458325589386287270351151382853513665715937106308511729529127964911372448, 14942961257346694397290743531880253247041391520120289699328554993194557045563, 56610619719645794589483526545092427325007943424492457507726642806493936061120, 61838211614666934910392440139437899360325983389254440010643629845091390969426, 1594630207817741980647680371133186282222244195826653301152099379855923258319, 39976143909302683029489041490306637160569309075129062861551966819113272994712, 63198778084454063566056243507718073288176408462904377832506329417703374070146, 12106776746215767660391184528484652896666605094900738362062329429770054842651, 70815365483499881576286614018289560828420950305307679037066862300925666709076, 34155599479028884409904546003583895555808300446163550648895501635054056483243, 47235041940312918011809632710968083587861944792395258754032944720043870810102, 11279460799877672005900296787855603884675607872517313200118064975802612397768, 10336359859053725303799676741278204219230539377055813682550722881699379229861, 24001433259710425078342861846750174290726772095512137488508098310985095212471, 7049674550373684262241332004630735541515205124083507220219609060235158802362, 50293087769094596576302261723136262446101556859234357197374860380714835632857, 55049561539142876216313528082109703360830592009526950861275669253490310828230, 24097757491647814932703635575963958511960435270387057288022919279012109086946, 62905262489519793240906650770706094701433331951407533976510922812426530634545, 69677625747030426028129240089875897587698802269852416057858391413793141342688, 28568799988015882159268699884165479053773466470198251445036573781621473843607, 48908708556147233348205238806248811526907324429222052931112659501432420733124, 75645908390275198838429192800346989316450137989356358514356982597865735402323, 60082563190048351844513479300762813796897774879268024358374332620104411916700, 16523709897084716737459125942868016279469453232477289276516765378562296165668, 63362549505482113440270099262939883171447274797538467413038944520364119516718, 26107425940292159002767387552475149278576449630558985120740293110004090893066, 2267247306370142331449210449023133969505848688804465371976618588938742175446, 4367582349579199965745584849752141603187801405653615613925001523622566142155, 71950093133753953422498906601803601409176253942448831811229176481313428824498, 59491775987458992228501582198728224766265155377250736591884564966816154899032, 60603274794520656742993725195503379914480534517451590572821020343649638467982, 12147679757794683622978226427989986716096751551025993146428355739926944490440, 9564942415680027280124646717782074670637906402338800428864342404989400083620, 27339035075687488604647651353802720326590480574210101944972930375883335285851, 21434270295179865588755759223298333792492764327605227471509726527574957086689, 38036319876998947747610454429574853328747761761359198496585873873948301686420, 34123071012005686047136416507535007458301856373801379312596381262854885103338, 26183449306325954767319451694773007535947028452350445994452962450262785471064, 33912225671968036455962599919081625150047015745659942172123196765629863143907, 35951020632065220561955396698826855129736709222130294457213709880995671352365, 30836911128127329019286649985341735952042155264997267855059287429460149096712, 69532642164321748473696939934926110085832676040501508996027260847608124929604, 10153079878853181057095274259436557838673301706653496304569888904761813085470, 13781625753984300810645757380400487905125752100752372784422127968148437719278, 67291930985685813727718088546813922299729682094604523855004454973224463379803, 70555628333491515495901306613211926697986451987386228309697345524751289035036, 53743776579048239754672091815633123314443157558369350543865632621816227287151, 68625421652391965076401674288319552477262023233333600080736610161381666691851, 68214961525407801292293774810170138395538315813015551932538265610474221437925, 108478603062379448396313690802578260586826385107457547966246050244586889653, 17850962271100788774733904414554594775032031250721378512309666279413256908100, 68401124053423238180932425785116129488963771067777390166978955053650007539174, 41308379551556870522997409220235826506467243065964428705301174356920983269545, 35460642824488567978742178792618486189604188650094694020645470247987130826009, 25927116776772079082443643840095689541439829653643797584560972580282532908317, 58212563959898367356241812575838609781580536191789263916786248567753460941758, 70081019734967724810472594115638455697796383162699658778850210145643708255055, 7318937013937943870960226972389592496964405573483918794866934831052999095028, 16386827908287810251482644751105836326199438044904669871099956113913486870178, 44601873468153349068313548398267810588501004724502949934074832089403404193285, 72365645959522403941725684789269335063058855406738177913754690862646950182843, 16771218590216980015793511028537692767302331361221481854551078801185971964147, 68498727060778643690889786451596469837396689531508387322367175471815038796235, 66505303613456331676754298818965827467846564046903223059321515134065968853381, 14103339333476369027283355473258973594184113562261155164803092812929087041002, 20149458131055400017813548765524380312378326777003730874778166862385843135367, 68362814397144998600704695153849734582744154023993460510385244305799785134657, 15791666226290439600140036379097225268374927472963559010684326326836557581106, 2252185449620911291377871638232740599539417178811979943420436329728757437052, 47698250136447118891314790959404361946127772532616124382854747980926566462430, 23186489809337051714797650239858764600558333074288416924025717609810056163889, 21764163973610747516126692766788224850151405280591445233076316314640271031882, 66189882479675007489330018463567650013283296464749593201753850526987949975416, 18349197902265641400051516596878539099698311348601920279047947082291648764209, 29534326948897865460972990466686282597968037449340555417908148354665508316311, 30761726002018157035512152020110436286407754168906922494902366469595925911547, 53470811125044570210268948746270880051866921377474524419805212771755689494239, 1718252715648064702128922609242974941733557502883869569146315179232997608448, 11387499294072063445562000942173949715804056241643381896707593832669694543533, 73190917948248307878355032820918428667254963054687203377103984221927729107329, 2754924808123516635322508269025982280348732792397898445374737750901419879892, 18392777520533775974331283458268583436805830250170822504575240887864404631258, 339857287167668726475727582116295455303066302702113718887477375482178913131, 11130644489292701093833211174262004002677773443507897198765923801116993268563, 19773468524801403668141715448569907183978558061962367756724671730514045670455, 30179599682305812383092811956530892131229888859754804552480182525253186087395, 62909185436282889899219419098553455168866163819284667959074524718726911872369, 19869570614667900091191055616123563195066117498648951198937139717994004755597, 74449446783591229529843871225569265771129896105452423402241634527178731886684, 63396677289466168962943044108919946383755210323418106557438390439855351241957, 41416147312741810450511037137963580300734196711090158231991707383784713097055, 54229031375784249713712749426113346917158761981749277572353515835808671169487, 38945934412719839619082893176722242458000574495271560956003825693153480739242, 16487090738884862710253652154283588099287933661516349462768417414855385888090, 43826999507232911403929036770652350249567515586351752321814902084933468871660, 3449200793915057262252455796662993918161789556798535902809795058957527335322, 41264121674084026284499114095557145512985657470422997288055899071338699929779, 64472937693232175320174536529491357253649254539383054954009874341776018343642, 74857293754800965593422507277945520778808275948585663404825604191786154926572, 5815401313116918143006631725509484645775007330033782585202345651872053808595, 37197896408873820874244421420831644361849255252055930907806522921208350775039, 64612516161759831629153934495914308735440301897133178083405160557284431288062, 6559843023820545053855833942571567076667408547751733575865753713103768351388, 23437859458185858514664667165353093105305612490482121637480297616471460022122, 20274295990762879799830790571682510221625279103061049956778950817733880775419, 56401143574723504944509185121746644273583780035351217559257907121927365401449, 49601992218738067701189706997135568168476724951148151719915502090514327693221, 341186914486664186771385431945363659110447477400294501019904692883991885913, 35034547603536685580523474143512924804215389058420557699907258381581548447058, 12200305304384520144709999256812132890182568366360405150906949960405768668212, 39082001882692927976859835410233841784024718778286445924310806205861631259877, 31385899040100510914187053148596292409959170884594053055923974443773698154508, 5835333348903500569738395009368766826900599549472035201775438526032338962832, 8073262852355325014634360942318701107854106520655139805022423637269325030952, 15201395730259063595486794416894052687408854909531507923325451061007646348912, 16427855579354233950275414209580340954569134729882232220122584282551493637784, 14939496218250709237679403125346973587984606820530045006556503486993199165868, 11472018317719132922440196176527154420012451882426166339081202168722507006391, 20562533742066382133554315281828262527674049070006798122553867931071494953097, 28524309930702578392587668311431861542844372396686280497129185069949980697887, 28383799886783235181459389725380167461672465671031363872148608556915934650821, 55858389045107938569827040507629525345474103343481046708180317803708122301591, 60130630314358998201961002540806426109698641115312889893545652213850027383317, 62568703748846586914004173002862196100010439494734550299970402141247677564480, 17072350907727140008641307409070995538642452783348448310992620875418467969325, 73713669713737928408393603793843892467892931893611774363620064726094232766451, 74924693780545798658596704166788134541217378161440448755639826167635348817201, 18868660066305006502591849005871664243845115744730952540180642652276775085293, 62340224361267634006286814100182579622129145288096554244391164203193515881749, 39627274282853089038123962325670720421395853551562914127393792454878764135694, 15875125499294992097449915335526612950522181082288770749491670123007795938830, 60347930680219965971015122873223017639063549778786148029298776837851386632197, 34804246576701738787777230859657047300861773235137871724401221304294655339922, 74533835097703506143597441265411820511880172767129948539794601205386044777692, 14313559485096981913264509436614352434539748805581872239992105363481732829367, 19171789603672277177031372245677531017754944212759999350309655106207957804079, 4968175301831692090292608692629174087333895759761745248376489165274706266140, 66639945794581084754753051281751407776097426324318667075086725551710264930290, 59129622729774783807536138073038505378065074618899090268492550568418148993817, 26330600192574911725030253530674667135249314930010022161561110487432679412346, 37881986704920521195794026228790435554661878645607329970186077787030456659000, 27701963450984409765947049999542882575142094924156220225677307089589870028275, 72583659346427605251468432495168368101442353233014061588652475808297035455520, 12989281482076173982092249100245773192037240577774571153957309897342475222983, 53632058799614335393892361774018122602253084706713924599291134300574903019263, 20629095213919844162761775592879555854908917555384903352158192223392004651847, 56964943703372619910676152072775721540805653363005415107771872381562741955707, 68258175306303746182752585969557329490259603293733362129509064175919040300035, 305059625297334113518421210177084300832046195491993511523415230959150990073, 29627101342558600381782480796033532526842782996378655001684599509787200614166, 63083188609616733628410982115889456461165904638544130382266320173120806597633, 26787135105784799411174671164943806509174770974851864542632539666931383923294, 23066937861699903064575204924379799292078776619882229043415335013240639787814, 45667754933572606110898663979907742452417927316570454983599210687471516167897, 14305984325362513624943911776711156769158238069530207305703314765820164002676, 14831302607678136122176302607664477491230563977695179542864281028342301024710, 51037535846798104819405365682536695438509423898887071739014597105930057998419, 48652369650371740655690259282449880747930148169789680102695166437643005057154, 71492013918335334326695792216149984614913026146966017429260406965750804333399, 16867947212719052891303320067120340503543671114624235990428765330449681436, 73153795081830390833986618172943844382356209528553123455517576050355688776421, 29898811131286422521246118406139753008373279313361851068708215082260704285093, 44380753726589115543898536715604464431803358814745567231003254087023278125824, 28108379633113198575413568955011902702769938460938785967518524380028624994265, 28358289655293158986635669238773905207507920781300060436619119106291970359443, 19920848903341336963434902484854707260554671313892340780418153954186042946379, 56404357261193882915914669050476018754919847279836580731159450057153595235354, 26955068855031090885997069113679442709145027634024379353826028271400627789514, 46919410443478545252523437804442059234017614273672686022027209018874653457945, 57974642082462673365757545097294623041253313070904113609253558507159565225848, 62910748878179883431977765511282925445221478599898014034682117091464608104375, 41825434614169389280942233622574957372686523794041804073185538032682171241299, 39176480473345396556027909249429577014354747976864427429163828423143115456346, 50771776778772460180946616763755986966728800933810714726146848203134035578043, 29634833793005329382601833800465647751190159016124488767981549343135828908568, 65535650339630683132316514902898786158169187634011500515811661482049169399011, 14457898428120714622842227300845828676787455966886884216218691279452858037021, 22751967367776513184207196442050134343461085155210009474278586994560117171204, 11729511490772837953955652665227118752756775424188659305364499215253423715438, 15789566757538937158938105539719000408154428860261010255639736638867095964778, 23240445069758350396695618693843563681627830257032646749119379850633259411290, 28242810972693074985503555116117311832919586119574897405101100504865585369240, 47453559192300590466181957141888962772728479360685128165473991527654656435151, 33039215149084714455769343931369837808821001333724496577370451256478328435103, 53952871349034967709708570687453773705342973975753778136392642600234209153958, 71159230176900090188265538027242589769738350211145076037147065381325814851881, 4295733538115639473511178974431656000491458882726394621256091205289071673747, 14836628031793152342428206106649168865191282879949262432290127036712291876402, 2597748403518739298354922786091066021205791271781959146296009797099187165741, 34927392879121980516322010858985102302769920279321437160145901071908795152354, 62245421549208037106736271122570790927624573878669953062980881715450316959314, 34112996342634610342610203612013397815191296698891267550924352771276390156797, 48361745712066250517413636759572062076329188102394048629020763127684453728224, 53397364219490215140533435564047966604689750181018874401158433933226517921900, 25334047344031509427131399230122578099376953527606993887922799651730761451619, 16205160293342452655841185463276242966521391986484484096730292291693250797604, 55563822793939811662468997513054832756010144395623935190537268603584805644827, 22114349202644461306169184577423044992016896956107066824825973217708308287116, 58695735806144401022975804584348837912162125885447517690557802000538437903378, 62725110257332629707399545726290115276445838074720620323269881894812426240679, 72740545121235936460444862790732485876972138180360176807966637248511390202687, 38864922104503648085491022134186410388141363612131609524900163278961538805733, 6247498858902805956542008003425674825514951325194472192178974156108361402749, 30648166516566441693759932456607317547733476012380883874434122970160880247865, 4575334954291461959300238118233126057327760627427519194764502389800603769311, 26723773897526045578700798200406415810129732323809340593034097219007693767854, 6281037362081143841956572043052603650992335167706387748769908464787308468116, 64286047714880861237184633243002930991489966703054078421265395334582627848932, 33818408610159843439047291985292606030182385527908458939427536161601340606500, 13609013542259741479595055902471609005249306799788738033790269414947854732629, 17536333299559413769278779555899593685006959541248796392802972326814918093248, 18542411638263264709758187416205171006507952876914760112442559278337229190468, 31846307469493034316838689952382906549343543129130420785699083222514237248697, 40592429062450574675035536492279226132878508761351666544199201526262149036841, 16070354072152084171251954256965650868127334909410310239796909435959081936546, 66536651726235320716025905422215915536286975298767682203686010158828435836422, 63270779796490661912896864051407657325313990441210502073013713188722504687202, 50652181520504076157357984563735967695339879803377239175496269836395534982946, 69540558045608743280398490296786655030621238466469982991343921076457859892940, 9841051212527423402731044947747280437008712156236340601824643614196211843274, 12072222018009015572844794012125711875706395783186099114640032625144896635637, 72419230614634083225561970387936606863520709109027207928733198765143960628549, 68236958587200491037437084980978920554330839811562873222255335298700415667849, 59331603199698090304807290138357223750101574056412462750232912383849681378085, 74049416996499094867700938158176620507912183088060301485677228398518810315308, 44589211804350556947586393168468085510624406350243223906451657367443079929310, 11722889880704782579636467834320145727215315468978673105078646852644144267302, 37162938201479628318221670413677559400634057715866847284306714513527750674945, 77991069668341617159462711549869846198981640129981167090704944318704115674, 24781325074095957562937506481915752661363803640103881644858900422306288107594, 50243394436655506401651990642654333034843737321908127591211346146733919698702, 4687442095492726629407063506774869319329506588382547411714227663275278730148, 48665673214235643977327797912745435942206989823180516039539449161268668431974, 74131491413435387119131792722727733759321126020981238229557810802823961991702, 47189904836234956626027292138719309126034135335815370939500027177471882713971, 66642336946744336804106101412855565097025008558851680802487967517455789735556, 39100372733134560391249654613242874470306770053063559688335189061474490770670, 36297514610067901982629018660863166180382473936564037667028601317491991540860, 17324149473313481441270662400440503406969190628735911302837720385800561684540, 42802542236449653261447468311512525596146034881422362728317294020745706813252, 25651626139042609821274522801014495194664487121861815773466154842331285580014, 21716541386578074685869691456061206430285733782385055679840762260951476166122, 25118740227793068650697511146427922183350190031672179227128187181026982602852, 6303338362653191359429840875638154590221214529554254398020317282924083430797, 11676823602923092202726518487432133136153160175716928324653897909896417377812, 22591527842537341294483145138410804137744418275229475690901502775329143898600, 15423465169192480181442356594804980261283721927836152132025601291491315262217, 52812609311392879213822230880621473875352775152002161311612738871397605863880, 21901474529203951179264708005591369522295919484211247102532107112869116078257, 19797638480369991652756574723879513200654975293893348736030544826044791556948, 32988016865606803311065174911158930953616176692859261085994695731044998880154, 15013720620266503710552310356736760039787771152262419663931415383640959944255, 53402948699555555850235236503365318293878053556599845866304850886181009545872, 578414726576963854876846913955619952112582994566716072456132976959884676179, 40466349321388782370223373531538345659737923443566152352256589514853112352198, 1880872771817929401422746887732401444754320797361077742359254586522061791227, 12047247386203611116264496398473894119847278156533141745303654172096885251156, 69936255505090807483097726275462417694819398874749133254493672186121798377200, 56189742534184179404452653989780779218184322976165328587052998625929343322623, 52236009337040761579658737818262052113202727822428351125061965646336627100741, 69602156301479647575919598967688239987914479074743572725062043540490654070257, 43275610870271333523729921390330711657817760080756599441857535230607760941411, 74801842670674570366950941554414694286416981233096278329410936531267480474569, 45523293713799774297869620313627743054021694164918818578543266334503113411324, 6224628148872498105530232773778180856237282756455349012259772098459006806701, 56101098821863605404331255553131939303182353871414861601368987041137915588237, 62514080568984452192743867809516234273763360672588340116364253250870707318521, 19649775237337628583259267760455078900133044996026852089604162480150727282031, 2681234746190183559749527177265047256319920111047263024620018491184772138292, 72477724874088708435244260512231062708354748933432591378948353186584708518437, 30252634827911264412522143493887618347186344100498154681798239667087055584973, 62928841586820277215525270906650454728386236998562125216494201758368148279508, 56211379382238646600328517905522392005714296756819673058449743612932975181011, 50094037173696920599812572028124311773584583077682555863904810763866337865415, 35317166218591202676897548502174130503664049068075924052208958517407974181419, 25506065854504640436633838443529482237490038072404045113454162320518595298079, 24598282043408933159434555506241937793897636834036366695267201954251938064858, 40359136257256317951754486181700633715943232386029795075349229741392377893448, 41753903921049595397751509756734177717249754689414242359419638438895614782681, 64879894430542426137516569367284410206800804149311771326329785080288758261071, 31682887186457559477375016497207344351697184042518871050776477362607703713335, 29968228072586790097820746477232816665998277976293252190030364133538849649097, 332255312561919030611963580501150855624827653577824313728984209608512608771, 33823033061488824234179656069812811550521458222627846709618871103804433549208, 40256197078476374288168370733269644672544776862251441956395184831531034573120, 63854791069720406920587264743813005867085205938858782942089091387745143688524, 9599189722183226358779095857498561886058642596617187395926371060462688656609, 15029540387621509138061041056904048961380890903724088755367710335622982174182, 4834678835879134834601247929812861614226805889003245637987605009945117449222, 49032287443959922585421022539339859727864184118407327061056787486660050994804, 51367113126213677371544088617641070281761594598856355289598680348862100934405, 48099687480283705985883062779219537419919474724954533559850612088090057306918, 55520602086715679118869322729503627581286641464273224324645023518549139088388, 50455510074969331802134040882996226109444134111548070407754215749016079079591, 47469806992474607142964806583892893209350327489840529459975202523406918697529, 44993893961585674228825543823064277790256859558754760867449903789983284056192, 44122596973664102569554815809415734634633243724572865236160697307096168452789, 51722296980185400816766674111348260571814278086142919892660507537043249830719, 2033567717312718757627805714157011922823676173550156447506958538133031286918, 40903326746018205875236484413558515226676475499740080681613680228360211918942, 45655754955370338497959237080418596437202658977517625068449957735452901887933, 13099233879696255324623677988804870917874154288631096861534955732046228968134, 44471530296771048523910819473361036714610802054279177471367823293743719275909, 25446261500563608722277325170677124816913924327250182158338980791838121166348, 20849472122256100875237011040249343324234928290319054354358242725759352931027, 7037043514495750961085179755568922433574397862705004833537643401449768094927, 24602719773333598554726432771595598259193579434836329001621386950000691219145, 18291650246498286332477867018368277382676465438496649012143967117655345637528, 45539989423554662584586894487111357151994014405213908150771179299468367899190, 48070107064454632531764035109162049005752680792201710661207400175358438021031, 7593113852866099746235678251926660680184416554718335029164595384991677535670, 61267284459965876196585417165926198770265833151343328469624242730879803451439, 3113616736283221407577816039505851478576505404761990976205583322559028256017, 29330053766980680089057055489775792668017015563299551837945432855633479513403, 38650331327684731179494096039889807053556745918527992295694445248090022667695, 11185985969572649911287822641562854469066291745462641774733857682450748347757, 6571676849591061846860086681136363771968700745359806059302040914080951597505, 47756994940258770519162165424758057472757403664170491681038228297319879170179, 32594475773547428735290676052531964976552484974356093150173758902449423156454, 31898634435507821969130133343503506337057311382300091683049093677942058183477, 8353498532203907327130477695937160917023156103120835230016413595452591896676, 72216190258743114705738161722736218780580609507689664769226245468683927077534, 70887162563386966001868090323354098874355491350818633411742235015483133077695, 53428119825008762677728594318441425057537661648075595012957502970943136262892, 32863943200860906581953022085708385110199346863351756782360531422328330178353, 69608025594463019257125425333532340909708104310858865262120126307135308366029, 33452066316790958427311031033544525015058584636612574435078141485268045480510, 67467748971757982782108778816344194052265871654600993221694391564870705065723, 4109223118757802968784775933084268418756424413308874230869847907255969302298, 874689888905623826173288368495929100158181002920189916388429819486644481023, 72378176399887630170201236756088580064855288788646391253391062547296108569964]
c = [53988415223839046381660672886792550892557190087087742629543368068682997090947, 21920921577840820689544269317401273370645213368453408007695580910149937697350, 29475771140129436159914858194223947593631108556842828359576509962355002130884, 31590148131791243731394919647376320328981021184223344832519185603844396786591, 40158574856962337545114912732379830254905090560850444592715018068912713975950, 50202503631530908716292345385552528345477433154392551391113477385703155787943, 25774597836388201526898377602793037428257024917440689218589384298072305574879, 63699495213620446235153554941891496976361246452059711453175708378318694602997, 20163212118036162236820095294493608896188807674678722559179017053183514140545, 19274318563716163915370869155502529679348083562418954598176006625003116718683, 61195117146757818795182876923087120232550209256816533077870026077903026793552, 64135143979846412750088422623420891325395709280682206900910074454563319174684, 21787908653560434902963868824798375507100016805476198412260169885990367978999, 8441422610194193525495290892888645173453076691768846248230542826479457290786, 24175440953264371229111128918926940451898832762196824660170198350642339016663, 59119734184764887826210301129920567765450070009167528626807613085641307427339]
M = matrix(ZZ, 32, 16, m)
E = diagonal_matrix([1] * 32)
P = diagonal_matrix([p] * 16)
C = matrix(ZZ, c)
L = block_matrix(ZZ, [[M,E], [P,0], [C,0]])
key = list(L.LLL()[1][16:])
for i in range(len(key)):
key[i] = abs(key[i])
key = bytes(key)
PR.<i> = PolynomialRing(ZZ)
f = i ^ 3 - 10 * i ^ 2 + 31 * i - 30
e = [i[0] for i in f.roots()]
grob = [175336555462486363373099551411803174933803940918372428249159666803182759268063415863987676455854054651631174131625763475189413468427467197699058719725221879406119373683175842618465694427132003565774900609456204965408254598477034791500576573579131820364396996254469692964946065509325801687720344376041097328929, 192597139210277682598060185912821582569043452465684540030278464832244948354365, 5415723658972576382153559473862560277755192970021711034483296770242757614573901416501357332661976379693731699836578087114136761491831672836130172409491889, 210713951733721296094981135225517096332793112439184310028590576805069783972692891743044656754643189870169698041576462365740899368554671164493356650858567594970345928936103914826926922045852943068526737627918609421198466329605091625, 93558120697660628972553751937347865465963385519812302371069578286123647411810258547153399045605149278436900736665388355004346922404097196048139360206875149390218160164739477798859206611473675859708579299466581718543909912951088772842957187413726251892347470983848602814387339449340072310561011153714207338630]
p, s, c = grob[0], grob[1], grob[2:]
PR.<x1, x2, x3> = PolynomialRing(Zmod(p))
f1 = x1 ^ e[2] - c[0]
f2 = x2 ^ e[1] - c[1]
f3 = x3 ^ e[0] - c[2]
f4 = x1 + x2 + x3 - s
f = [f1, f2, f3, f4]
res = Ideal(f).groebner_basis()
point = {x1: 1, x2: 2, x3: 3}
c_long= [poly.subs(point) for poly in res]
for i in range(3):
c_long[i] = int(p - c_long[i])
c_bytes = BytesArray(c_long)
S_bytes = ArrayXor(c_bytes, key)
flag = [i[:12].decode() for i in S_bytes]
print(''.join(flag))