前几天学长发来了五道题,由于夹杂着考试忙着复习没来得及看,只研究出了其中一道题,现在看了看wp感觉这些题还是有很大价值的,来分享一下

Euler

题目:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from secret import flag
from Crypto.Util.number import *
import random

p = getPrime(1024)
q = getPrime(1024)
e = 65537
d = inverse(e, (p-1)*(q-1))
n1 = p*q
print('d =', d)
print('n1 =', n1)

n2 = 1
while True:
tmp = getPrime(20)
for i in range(random.randint(1, 10)):
n2 *= tmp
if int(n2).bit_length() > 4096:
break
m = bytes_to_long(flag)
e = p
c = pow(m,p,n2)
print(f"n2 = {n2}")
print(f"c = {c}")

'''
d = 1191103734504058491421349604548564929848616842152689496895544381837156883533438743584190765148552934760581271144506002162145850044043706855922892271482076871873995241085136144968243140990856473896170280564822732549232192446031619309897442553542363254504471740017966570662964696395047018142115398837264339359703632345253800336497946214283448557066829445107164480953216959246058743836325220516737638124436265379246043689904351250933647836622874758885644860021461954464385862680106712884194095768373281466098064819110033091294767089010003022970009602841916377292236136049332199074587736162893766795170383769105855396481
n1 = 13580613334758608446812976519363134969987613428002924766535019511562587104406919787452524386837284913953412450765046949147625708826808005604839699164252065405707381022094044455947068672776228380259796742758661695038105462132145830673755861626914728707456430832560451486001864528121467715375751025330165798298234749333641286199156268444951660172758198564829589895780644285230824166251980165312273600373379395893191960302458674257328572576250700441136204817923980559222287090491322038600230306017349810608247758292597409739448697047571469597942133677889648017239246044193456551115423543297398389835141582226233401091651
n2 = 1214806402018035399640161601350276689119300500885922730338627878893519991129980125476434307328318616551645952775278810103829168554249376991124646974529506458637833256309925386195767085673143119319959502919427611337245914269082657148902705137556296048781578971739222821624583120801659535369927877985173236243714461317935517361255270715241189816284530991305321818355420570545833978683123138276923580243415962479127687019106264574314649544746346086459905012212977958967691480715239783822121874583716717022133331534258680100103894980839994381411182849477289831563331555051111524494710894174250831042393260657010039224282544484051247017811298503920278914985702602401902771910416165113998593372720867385848641975504106450347785422029536444684536992419844582901814455572310411304170053743720539065216022165732393062765647406642461667856590659949987014165020908912248704605394194332522772838334355686250772722614893659631917281850223784937395431499960460631775969046704990152101465734651932493302101064276553602695086721483441047849063689763309160624353722539937307711289340553305706186969043326282042780389837191270199164643251358171042535614702470861637110776902483824241373428279843481575953477705679020507998934443944753893015492521729164439
c = 829714996515560908603942343505920996556339059436557287421074174277687809974667533248085244071086827486112801279665776466949992570288124598686592774771062800764512333540404127622921352174419248968970404794754685847236748961563984628001223295272803310968932487079932521884266677193760840062257399310444131681778575116034804962240312440452076927109544707668525304555494031530153484385014733733295665648179563341929829366393842180933029552234342383165468329118358481709562138556464490952636983157762226775051069620144327191146321078089031134997806488306619954921967209307290224398561337468466377749200533482249418692505335754212596152956893594720809675348504752525191974229476876972508737538861376367290460994163758533707257433535992369795872961693633915923559165304176024241693969803856234404053572424185908635089962296448104233424369921110004610276316317120909034370571217382030431552784144041430129071509829206755292634358474170376986660230213480604735611696589811824530116203051420922042313844629631979060959674508082246111229472102010511440894011705450255517464228219748967389876595425302704439665665510611452129328353818804395006155136491014104673084625985358676817967767734690717397046423097222254342558118886724303282396865112622135
'''

题目看起来复杂,但是看懂了代码还是比较容易的。

因为对c的加密使用的指数是p,所以我们需要先分解n1,题目给了n,e,d:

1
2
3
4
5
6
7
8
9
10
11
12
13
def getpq(n,e,d):
p = 1
q = 1
while p==1 and q==1:
k = d * e - 1
g = random.randint ( 0 , n )
while p==1 and q==1 and k % 2 == 0:
k =k//2
y = pow(g,k,n)
if y!=1 and gmpy2.gcd(y-1,n)>1:
p = gmpy2.gcd(y-1,n)
q = n//p
return p,q

对c进行加密的模数为n2,所以我们还需要对n2进行分解,求出欧拉函数,这里注意到n2的生成法则:

1
2
3
4
5
6
7
n2 = 1
while True:
tmp = getPrime(20)
for i in range(random.randint(1, 10)):
n2 *= tmp
if int(n2).bit_length() > 4096:
break

生成用了非常多的20位的指数,我的想法是从20位遍历找到所有因子,存到数组里便于处理数据:

这里还要提醒一下getPrime的生成,由于2的n-1次方为n位长,所以我们遍历要在2的19次方到20次方之间:

1
2
3
4
5
6
7
8
9
10
11
12
def n2list(n):
list=[]
i=524288
while 1:
if n%i==0:
n=n//i
list.append(int(i))
else:
i=gmpy2.next_prime(i)
if n==1:
print(set(list))
return list

最后求欧拉函数解RSA即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from Crypto.Util.number import *
import gmpy2
import random

def n2list(n):
list=[]
i=524288
while 1:
if n%i==0:
n=n//i
list.append(int(i))
else:
i=gmpy2.next_prime(i)
if n==1:
print(set(list))
return list

def getpq(n,e,d):
p = 1
q = 1
while p==1 and q==1:
k = d * e - 1
g = random.randint ( 0 , n )
while p==1 and q==1 and k % 2 == 0:
k =k//2
y = pow(g,k,n)
if y!=1 and gmpy2.gcd(y-1,n)>1:
p = gmpy2.gcd(y-1,n)
q = n//p
return p,q

e = 65537
d = 1191103734504058491421349604548564929848616842152689496895544381837156883533438743584190765148552934760581271144506002162145850044043706855922892271482076871873995241085136144968243140990856473896170280564822732549232192446031619309897442553542363254504471740017966570662964696395047018142115398837264339359703632345253800336497946214283448557066829445107164480953216959246058743836325220516737638124436265379246043689904351250933647836622874758885644860021461954464385862680106712884194095768373281466098064819110033091294767089010003022970009602841916377292236136049332199074587736162893766795170383769105855396481
n1 = 13580613334758608446812976519363134969987613428002924766535019511562587104406919787452524386837284913953412450765046949147625708826808005604839699164252065405707381022094044455947068672776228380259796742758661695038105462132145830673755861626914728707456430832560451486001864528121467715375751025330165798298234749333641286199156268444951660172758198564829589895780644285230824166251980165312273600373379395893191960302458674257328572576250700441136204817923980559222287090491322038600230306017349810608247758292597409739448697047571469597942133677889648017239246044193456551115423543297398389835141582226233401091651
n2 = 1214806402018035399640161601350276689119300500885922730338627878893519991129980125476434307328318616551645952775278810103829168554249376991124646974529506458637833256309925386195767085673143119319959502919427611337245914269082657148902705137556296048781578971739222821624583120801659535369927877985173236243714461317935517361255270715241189816284530991305321818355420570545833978683123138276923580243415962479127687019106264574314649544746346086459905012212977958967691480715239783822121874583716717022133331534258680100103894980839994381411182849477289831563331555051111524494710894174250831042393260657010039224282544484051247017811298503920278914985702602401902771910416165113998593372720867385848641975504106450347785422029536444684536992419844582901814455572310411304170053743720539065216022165732393062765647406642461667856590659949987014165020908912248704605394194332522772838334355686250772722614893659631917281850223784937395431499960460631775969046704990152101465734651932493302101064276553602695086721483441047849063689763309160624353722539937307711289340553305706186969043326282042780389837191270199164643251358171042535614702470861637110776902483824241373428279843481575953477705679020507998934443944753893015492521729164439
c = 829714996515560908603942343505920996556339059436557287421074174277687809974667533248085244071086827486112801279665776466949992570288124598686592774771062800764512333540404127622921352174419248968970404794754685847236748961563984628001223295272803310968932487079932521884266677193760840062257399310444131681778575116034804962240312440452076927109544707668525304555494031530153484385014733733295665648179563341929829366393842180933029552234342383165468329118358481709562138556464490952636983157762226775051069620144327191146321078089031134997806488306619954921967209307290224398561337468466377749200533482249418692505335754212596152956893594720809675348504752525191974229476876972508737538861376367290460994163758533707257433535992369795872961693633915923559165304176024241693969803856234404053572424185908635089962296448104233424369921110004610276316317120909034370571217382030431552784144041430129071509829206755292634358474170376986660230213480604735611696589811824530116203051420922042313844629631979060959674508082246111229472102010511440894011705450255517464228219748967389876595425302704439665665510611452129328353818804395006155136491014104673084625985358676817967767734690717397046423097222254342558118886724303282396865112622135
n1 = 13580613334758608446812976519363134969987613428002924766535019511562587104406919787452524386837284913953412450765046949147625708826808005604839699164252065405707381022094044455947068672776228380259796742758661695038105462132145830673755861626914728707456430832560451486001864528121467715375751025330165798298234749333641286199156268444951660172758198564829589895780644285230824166251980165312273600373379395893191960302458674257328572576250700441136204817923980559222287090491322038600230306017349810608247758292597409739448697047571469597942133677889648017239246044193456551115423543297398389835141582226233401091651
p,q=getpq(n1,e,d)
list=n2list(n2)

l=[628097, 724993, 610187, 895243, 1013773, 610447, 725909, 971029, 1022869, 598687, 802721, 795943, 621611, 986411, 1009199, 592561, 897461, 771769, 906809, 752701, 668093, 571583, 1020989, 810307, 661189, 940229, 638663, 987463, 921931, 590797, 725209, 635737, 684767, 559973, 763753, 973801, 811771, 918397, 667519]
num=[]
for i in l:
t=0
for j in list:
if j==i:
t+=1
if j>i:
break
num.append(t)
print(num)

phi=1
for i in range(len(num)):
phi*=(l[i]**(num[i]-1))*(l[i]-1)
e=q
d=gmpy2.invert(e,phi)
m=pow(c,d,n2)
print(long_to_bytes(m).decode("utf-8"))

看了看wp,wp用了sage里面的求phi的函数,理论上讲大数有很多因子的比较容易分解,我试了试sympy库的totient函数,也能直接解出来,节省代码量:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from Crypto.Util.number import *
import gmpy2
import random
import sympy

def getpq(n,e,d):
p = 1
q = 1
while p==1 and q==1:
k = d * e - 1
g = random.randint ( 0 , n )
while p==1 and q==1 and k % 2 == 0:
k =k//2
y = pow(g,k,n)
if y!=1 and gmpy2.gcd(y-1,n)>1:
p = gmpy2.gcd(y-1,n)
q = n//p
return p,q

e = 65537
d = 1191103734504058491421349604548564929848616842152689496895544381837156883533438743584190765148552934760581271144506002162145850044043706855922892271482076871873995241085136144968243140990856473896170280564822732549232192446031619309897442553542363254504471740017966570662964696395047018142115398837264339359703632345253800336497946214283448557066829445107164480953216959246058743836325220516737638124436265379246043689904351250933647836622874758885644860021461954464385862680106712884194095768373281466098064819110033091294767089010003022970009602841916377292236136049332199074587736162893766795170383769105855396481
n1 = 13580613334758608446812976519363134969987613428002924766535019511562587104406919787452524386837284913953412450765046949147625708826808005604839699164252065405707381022094044455947068672776228380259796742758661695038105462132145830673755861626914728707456430832560451486001864528121467715375751025330165798298234749333641286199156268444951660172758198564829589895780644285230824166251980165312273600373379395893191960302458674257328572576250700441136204817923980559222287090491322038600230306017349810608247758292597409739448697047571469597942133677889648017239246044193456551115423543297398389835141582226233401091651
n2 = 1214806402018035399640161601350276689119300500885922730338627878893519991129980125476434307328318616551645952775278810103829168554249376991124646974529506458637833256309925386195767085673143119319959502919427611337245914269082657148902705137556296048781578971739222821624583120801659535369927877985173236243714461317935517361255270715241189816284530991305321818355420570545833978683123138276923580243415962479127687019106264574314649544746346086459905012212977958967691480715239783822121874583716717022133331534258680100103894980839994381411182849477289831563331555051111524494710894174250831042393260657010039224282544484051247017811298503920278914985702602401902771910416165113998593372720867385848641975504106450347785422029536444684536992419844582901814455572310411304170053743720539065216022165732393062765647406642461667856590659949987014165020908912248704605394194332522772838334355686250772722614893659631917281850223784937395431499960460631775969046704990152101465734651932493302101064276553602695086721483441047849063689763309160624353722539937307711289340553305706186969043326282042780389837191270199164643251358171042535614702470861637110776902483824241373428279843481575953477705679020507998934443944753893015492521729164439
c = 829714996515560908603942343505920996556339059436557287421074174277687809974667533248085244071086827486112801279665776466949992570288124598686592774771062800764512333540404127622921352174419248968970404794754685847236748961563984628001223295272803310968932487079932521884266677193760840062257399310444131681778575116034804962240312440452076927109544707668525304555494031530153484385014733733295665648179563341929829366393842180933029552234342383165468329118358481709562138556464490952636983157762226775051069620144327191146321078089031134997806488306619954921967209307290224398561337468466377749200533482249418692505335754212596152956893594720809675348504752525191974229476876972508737538861376367290460994163758533707257433535992369795872961693633915923559165304176024241693969803856234404053572424185908635089962296448104233424369921110004610276316317120909034370571217382030431552784144041430129071509829206755292634358474170376986660230213480604735611696589811824530116203051420922042313844629631979060959674508082246111229472102010511440894011705450255517464228219748967389876595425302704439665665510611452129328353818804395006155136491014104673084625985358676817967767734690717397046423097222254342558118886724303282396865112622135
n1 = 13580613334758608446812976519363134969987613428002924766535019511562587104406919787452524386837284913953412450765046949147625708826808005604839699164252065405707381022094044455947068672776228380259796742758661695038105462132145830673755861626914728707456430832560451486001864528121467715375751025330165798298234749333641286199156268444951660172758198564829589895780644285230824166251980165312273600373379395893191960302458674257328572576250700441136204817923980559222287090491322038600230306017349810608247758292597409739448697047571469597942133677889648017239246044193456551115423543297398389835141582226233401091651
p,q=getpq(n1,e,d)
phi=sympy.totient(n2)
e=q#注意不确定p和q是否和题目中的对应,如果没出flag就换另一个因子
d=gmpy2.invert(e,int(phi))
m=pow(c,d,n2)
print(long_to_bytes(m).decode("utf-8"))

EasyNumber

题目:

1
2
3
4
5
6
7
8
9
10
11
12
from secret import flag
from Crypto.Util.number import *

m = bytes_to_long(flag)
assert m.bit_length() < 200
B = getPrime(1024)
A = (2022-2023*m) % B
leak = pow(2, 2023, B)
print(A)
print(leak)
# 170552035590584371794277768762390230763544207477112166060533204313753004629936685595405184205281232276007015670211368033442806936779308867580378436822021847321737051586882192693878924902157737728943995367527577690099125847661701232120507334675776645787433344767625337798357285176902699598449086385213291366162
# 66573767005779268080495621179078972426265588843146030764009851250207246081886465887129685885427908408673076322868864723505267053962926489662364269721110570269848306490343161117767892544708463436083630857549295570803296389232068947551581525974801496469745646172924950992026908012083467414933570463776905332979

这道题目提到了flag的位数,m的位数较小,根据后面的计算A和leak大概可以知道这里使用Coppersmith求解小值m,构造f直接求就出来了:

1
2
3
4
5
6
7
8
9
10
11
12
13
#sage
from Crypto.Util.number import *

leak=66573767005779268080495621179078972426265588843146030764009851250207246081886465887129685885427908408673076322868864723505267053962926489662364269721110570269848306490343161117767892544708463436083630857549295570803296389232068947551581525974801496469745646172924950992026908012083467414933570463776905332979
A=170552035590584371794277768762390230763544207477112166060533204313753004629936685595405184205281232276007015670211368033442806936779308867580378436822021847321737051586882192693878924902157737728943995367527577690099125847661701232120507334675776645787433344767625337798357285176902699598449086385213291366162

KB=pow(2,2023)-leak
PR.<m>=PolynomialRing(Zmod(KB))
f=A+2023*m-2022
f=f.monic()
x=f.small_roots(X=2^200,beta=0.4)
m=x[0]
print(long_to_bytes(int(m)))

My_Enc

题目:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from secret import flag
import random

def Cyber_key(LEN):
Key = [[] for i in range(row)]
for x in range(row):
for i in range(LEN):
Key[x].append(random.randint(0, 2023))
return Key

def Punk_enc(Key, msg):
out = []
for l in Key:
s = 0
for x, y in zip(l, msg):
s += (x * y) % P
s %= P
out.append(s)
return out

if __name__ == '__main__':
P = 2048
row = 66
key = Cyber_key(len(flag))
c = Punk_enc(key, flag)
print(key)
print(c)

'''
[[505, 469, 528, 1798, 373, 987, 981, 438, 1438, 1918, 768, 980, 720, 336, 1763, 585, 1582, 1020, 601, 1543, 1374, 1904, 340, 326, 947, 639, 1143, 371, 359, 953, 74, 657, 13, 359, 280, 1903, 687, 371, 114, 1232, 1573, 743], [1310, 205, 491, 137, 1743, 1185, 74, 1797, 867, 755, 967, 454, 800, 568, 625, 492, 1835, 1586, 1462, 619, 760, 1144, 98, 1764, 1356, 991, 1392, 816, 849, 259, 1305, 842, 1250, 1983, 1339, 752, 1170, 1976, 958, 1710, 1216, 1927], [1507, 1699, 1536, 1708, 739, 902, 1169, 1352, 886, 680, 1400, 1011, 132, 1561, 1001, 772, 1809, 208, 1161, 1691, 2015, 1099, 166, 1571, 551, 847, 663, 749, 1634, 1487, 960, 1675, 1017, 109, 63, 1714, 1540, 1515, 1382, 1569, 851, 985], [451, 1919, 680, 76, 707, 1283, 933, 658, 945, 1801, 352, 673, 1072, 48, 1994, 1923, 1685, 1684, 1374, 28, 1774, 1769, 1388, 1541, 604, 107, 1290, 787, 1622, 711, 323, 1846, 317, 1519, 1426, 123, 2015, 861, 544, 1401, 1869, 1833], [862, 1316, 393, 1190, 2012, 687, 78, 61, 1391, 1238, 1282, 866, 1385, 1200, 292, 1702, 1599, 712, 1108, 653, 1711, 745, 100, 275, 322, 1671, 1723, 895, 661, 1726, 497, 342, 1010, 47, 1204, 1911, 1734, 1567, 1892, 954, 386, 1996], [1333, 1928, 191, 1502, 1106, 579, 779, 512, 313, 308, 1277, 1547, 1814, 1434, 1867, 670, 543, 404, 1570, 179, 555, 1896, 289, 492, 1874, 1190, 1885, 748, 1375, 401, 1685, 618, 1614, 288, 2017, 571, 670, 873, 98, 563, 180, 749], [262, 1072, 1188, 864, 960, 1069, 1931, 870, 573, 44, 38, 1525, 41, 1197, 1618, 857, 187, 804, 1828, 1525, 96, 204, 1565, 419, 1397, 1487, 1902, 1150, 650, 1562, 151, 564, 1836, 826, 95, 158, 495, 1357, 2005, 819, 783, 880], [636, 985, 809, 1165, 1478, 998, 408, 1897, 988, 421, 743, 1210, 1128, 1901, 943, 512, 1587, 1784, 911, 857, 434, 367, 1345, 104, 143, 357, 426, 1169, 1876, 1111, 1355, 371, 219, 1056, 432, 780, 1798, 151, 210, 1293, 807, 620], [29, 440, 1323, 1960, 1791, 1084, 777, 1314, 709, 1014, 1721, 108, 3, 961, 1253, 245, 862, 1899, 1519, 563, 347, 870, 820, 1787, 1323, 1113, 150, 1108, 1547, 1438, 845, 788, 1221, 1680, 795, 923, 1308, 1114, 153, 1985, 573, 132], [1979, 1831, 1374, 601, 1736, 1778, 1390, 138, 1295, 1582, 1777, 362, 647, 753, 627, 142, 1732, 994, 1911, 227, 1069, 1943, 1206, 1266, 1605, 827, 1153, 1375, 486, 1222, 1938, 794, 909, 629, 1232, 756, 935, 1374, 1148, 1312, 584, 901], [631, 136, 1835, 686, 1779, 1298, 1471, 1009, 107, 906, 4, 201, 859, 1808, 1743, 1286, 305, 266, 1374, 992, 531, 389, 1482, 362, 873, 533, 341, 1357, 85, 424, 207, 995, 275, 857, 1239, 770, 1355, 516, 178, 1560, 228, 1843], [1863, 1423, 786, 209, 1565, 1735, 1662, 1571, 749, 326, 1258, 1099, 1780, 1240, 865, 810, 7, 301, 1926, 692, 67, 978, 1172, 641, 839, 505, 1106, 423, 827, 1838, 388, 1749, 483, 880, 454, 773, 1961, 1153, 858, 963, 92, 829], [2009, 66, 520, 1027, 1804, 882, 42, 1826, 1732, 1093, 78, 1826, 1948, 734, 1486, 1285, 28, 1092, 174, 292, 1412, 24, 1454, 1015, 1560, 1154, 1168, 704, 1224, 1422, 784, 1353, 799, 1591, 613, 1318, 1623, 1151, 968, 297, 953, 1178], [1889, 727, 1189, 160, 1198, 1338, 970, 168, 1737, 1356, 1525, 590, 1773, 1397, 105, 1368, 401, 1569, 287, 1757, 801, 1818, 309, 1416, 1721, 1403, 1086, 583, 1203, 172, 1030, 647, 1497, 1222, 1581, 432, 1199, 1279, 5, 570, 556, 1936], [1514, 1162, 130, 1023, 538, 1772, 1525, 1709, 774, 1904, 1489, 837, 742, 797, 446, 1240, 847, 624, 1629, 2011, 867, 1097, 1814, 231, 381, 46, 363, 1560, 786, 1706, 800, 112, 748, 745, 407, 1290, 1093, 1268, 1536, 129, 1632, 1200], [698, 1238, 1100, 591, 1166, 1320, 620, 1044, 984, 744, 453, 1927, 1019, 1488, 1586, 1428, 412, 42, 776, 548, 2006, 409, 1767, 506, 1153, 1398, 391, 1597, 1794, 1203, 1034, 180, 433, 989, 1308, 1342, 1041, 1461, 782, 1284, 225, 492], [342, 15, 324, 551, 329, 1427, 186, 932, 774, 275, 311, 1562, 1557, 455, 329, 66, 0, 856, 792, 849, 878, 1362, 304, 1004, 1093, 1768, 793, 366, 965, 932, 1548, 759, 990, 1033, 720, 1344, 1438, 481, 1546, 985, 51, 1915], [1737, 1934, 1414, 131, 1328, 919, 569, 1731, 1771, 43, 1622, 322, 2000, 1918, 384, 995, 1282, 1380, 449, 1566, 1981, 286, 981, 704, 640, 551, 5, 1019, 598, 1079, 1150, 209, 464, 1555, 2, 1988, 1305, 127, 152, 701, 553, 1030], [817, 176, 737, 657, 1507, 514, 1453, 1656, 1229, 315, 368, 332, 460, 933, 1553, 1409, 1137, 1910, 209, 1906, 1487, 571, 996, 1489, 2011, 245, 1510, 115, 1155, 349, 67, 620, 759, 699, 1034, 1030, 984, 70, 1585, 1580, 121, 2], [526, 1875, 273, 1552, 641, 532, 613, 1092, 72, 1518, 600, 1380, 1088, 1371, 143, 1764, 1695, 1747, 1693, 2006, 614, 305, 1784, 1474, 1761, 730, 1968, 1803, 520, 917, 1976, 838, 525, 1769, 2005, 1625, 128, 728, 1729, 440, 288, 1530], [17, 1580, 403, 1813, 1514, 1603, 559, 1845, 408, 1942, 966, 1393, 544, 272, 1400, 1940, 412, 1968, 837, 945, 503, 409, 154, 264, 379, 218, 1847, 966, 1103, 125, 1935, 1381, 1552, 126, 1379, 397, 735, 1165, 162, 1696, 44, 238], [1401, 75, 99, 633, 922, 1093, 831, 1422, 1489, 46, 728, 1191, 292, 473, 640, 423, 766, 1991, 1561, 1897, 583, 385, 409, 1814, 1684, 879, 1414, 160, 1870, 577, 1394, 1088, 1248, 1425, 405, 1726, 77, 726, 1070, 642, 935, 1105], [1156, 765, 913, 323, 888, 727, 1826, 744, 54, 1009, 1790, 185, 1498, 1599, 1069, 62, 59, 32, 1280, 274, 728, 1831, 1879, 175, 708, 1466, 589, 263, 707, 1542, 1790, 1816, 1854, 992, 1402, 1354, 1501, 1200, 1653, 1067, 1756, 573], [645, 378, 356, 1474, 837, 1664, 45, 259, 289, 231, 1640, 244, 1864, 1022, 741, 1741, 1594, 1353, 991, 2002, 1969, 1522, 1852, 1031, 1296, 347, 1005, 1506, 760, 630, 462, 1302, 454, 466, 163, 488, 1239, 1554, 1482, 1918, 1394, 1244], [199, 1336, 969, 526, 2009, 801, 1762, 1185, 645, 1577, 1303, 707, 1731, 1212, 341, 121, 1984, 1108, 1794, 1078, 404, 248, 36, 42, 1757, 1051, 1485, 1542, 442, 666, 1596, 335, 1527, 1707, 1035, 1924, 386, 1566, 1509, 998, 977, 328], [1802, 1664, 1315, 607, 95, 477, 1534, 834, 1199, 1330, 738, 1339, 1313, 294, 1860, 1693, 2014, 1663, 549, 298, 1076, 618, 59, 749, 995, 1369, 558, 1703, 656, 1745, 1813, 1428, 612, 12, 624, 111, 850, 456, 596, 817, 383, 630], [221, 207, 1253, 1353, 992, 1732, 1038, 325, 1696, 662, 771, 1437, 1616, 396, 1568, 476, 232, 220, 1945, 1500, 1865, 1477, 1540, 1608, 823, 255, 342, 1912, 733, 1450, 1600, 1838, 69, 32, 1392, 1647, 820, 492, 1479, 1172, 993, 1412], [1207, 930, 69, 289, 1770, 162, 1442, 1071, 1598, 1900, 1409, 433, 1248, 1668, 314, 1201, 425, 334, 1373, 789, 975, 177, 1526, 49, 29, 174, 885, 264, 437, 287, 167, 1332, 1870, 1330, 1789, 372, 140, 1697, 1018, 642, 1894, 1829], [1710, 1301, 511, 1837, 116, 1749, 1727, 1479, 950, 951, 1104, 866, 838, 1248, 911, 988, 1275, 637, 1636, 250, 1603, 1783, 1821, 149, 388, 1474, 1366, 1788, 1038, 4, 201, 1003, 1246, 1914, 233, 1625, 1041, 1979, 649, 665, 1381, 1522], [855, 35, 317, 97, 400, 800, 107, 91, 1444, 1063, 552, 1363, 600, 767, 1313, 1117, 769, 541, 1466, 848, 935, 1918, 555, 1218, 1750, 1953, 1103, 1969, 1289, 634, 1310, 182, 1071, 1959, 544, 462, 377, 1696, 1597, 1936, 1285, 367], [598, 1990, 750, 584, 227, 1392, 1493, 748, 1671, 224, 1360, 1094, 1994, 1792, 1140, 779, 1939, 361, 289, 1235, 213, 517, 1485, 1390, 804, 132, 920, 536, 1235, 837, 298, 1139, 961, 1521, 431, 76, 2019, 884, 1991, 522, 342, 1609], [114, 1608, 1127, 722, 97, 140, 218, 617, 475, 1680, 214, 1595, 1373, 2021, 1031, 1243, 1526, 1562, 134, 684, 1178, 951, 1470, 1293, 1562, 744, 424, 336, 932, 897, 42, 1968, 1144, 195, 686, 46, 1032, 230, 1285, 132, 1514, 169], [1870, 622, 830, 283, 713, 1893, 270, 573, 732, 1233, 246, 1408, 1890, 119, 1529, 396, 1522, 486, 1371, 211, 1196, 671, 200, 1390, 1790, 547, 567, 1315, 1782, 1661, 756, 6, 1864, 626, 1318, 694, 1632, 1177, 1128, 1327, 405, 1283], [1714, 277, 1154, 369, 1472, 417, 541, 1244, 638, 1332, 512, 492, 1272, 929, 551, 34, 954, 362, 75, 1009, 725, 1481, 952, 1297, 1612, 289, 1684, 817, 112, 1731, 837, 1820, 1457, 1411, 1836, 454, 1984, 178, 46, 552, 282, 720], [1602, 921, 919, 637, 25, 1052, 1246, 831, 1332, 1664, 260, 1387, 1660, 19, 839, 844, 1934, 1606, 970, 539, 992, 1401, 1804, 1879, 297, 1325, 1671, 128, 667, 1169, 808, 1238, 366, 1409, 1369, 1997, 1775, 1586, 746, 278, 1134, 464], [1441, 1529, 415, 494, 1784, 1042, 799, 1701, 985, 404, 734, 1123, 1206, 1493, 1446, 562, 161, 1737, 1943, 753, 1782, 1341, 794, 333, 891, 973, 1656, 1995, 228, 523, 882, 228, 1010, 212, 262, 1948, 1573, 104, 767, 1607, 1333, 650], [918, 1741, 1195, 247, 2001, 1290, 1640, 1655, 1209, 1171, 1686, 1565, 1347, 1245, 350, 1234, 1271, 724, 213, 1994, 974, 677, 415, 1728, 1465, 222, 425, 616, 1649, 1114, 285, 753, 593, 1795, 552, 192, 247, 1286, 1995, 304, 402, 240], [1870, 843, 803, 905, 1256, 1668, 1850, 592, 1745, 1551, 957, 1095, 1492, 1413, 1604, 1944, 1424, 543, 169, 1811, 240, 996, 524, 556, 1189, 746, 1166, 157, 303, 965, 1848, 472, 1559, 419, 932, 2022, 966, 943, 1507, 1126, 1179, 1316], [1984, 296, 1135, 779, 530, 1212, 1122, 113, 805, 108, 990, 897, 1372, 774, 940, 633, 999, 1113, 873, 1933, 233, 236, 1006, 1767, 1575, 736, 1530, 843, 1373, 526, 1863, 2022, 189, 291, 1746, 1804, 769, 1355, 1745, 1355, 368, 666], [1714, 1278, 333, 2002, 379, 1788, 75, 174, 1369, 376, 1881, 553, 928, 1269, 1930, 622, 223, 278, 528, 1001, 918, 1018, 903, 1133, 420, 1389, 1796, 488, 410, 481, 1499, 228, 811, 1539, 91, 499, 1715, 249, 809, 1040, 1862, 1284], [560, 156, 1508, 1302, 194, 1062, 49, 1000, 1670, 1094, 1565, 1982, 1848, 204, 1846, 1565, 186, 1701, 1233, 855, 555, 938, 1489, 945, 1205, 1036, 1093, 47, 416, 1832, 173, 801, 684, 10, 1729, 1931, 27, 461, 1619, 1468, 1069, 1455], [270, 476, 948, 1474, 1209, 1968, 1193, 1683, 223, 1220, 730, 1122, 825, 1479, 922, 1684, 1526, 1532, 474, 1444, 1509, 1176, 1069, 1505, 1024, 1845, 1114, 762, 428, 893, 2012, 182, 1288, 851, 780, 228, 1393, 1834, 314, 402, 349, 189], [1677, 1049, 606, 1404, 1606, 164, 251, 1134, 893, 834, 680, 1260, 1428, 1743, 1658, 298, 705, 1450, 1064, 207, 787, 1094, 545, 559, 131, 1110, 1402, 1671, 545, 1885, 241, 525, 1333, 268, 710, 1602, 925, 1713, 1390, 458, 292, 1982], [1928, 173, 1894, 177, 1485, 2019, 1602, 1975, 1394, 813, 695, 998, 451, 859, 1913, 1307, 1200, 1900, 193, 1288, 509, 1568, 1664, 698, 1737, 1310, 1582, 634, 630, 1773, 315, 1225, 955, 195, 364, 1952, 1514, 107, 1103, 851, 194, 782], [264, 1210, 1424, 774, 1867, 33, 1584, 76, 1170, 1217, 1404, 218, 419, 1478, 1780, 600, 480, 1559, 1687, 418, 963, 164, 1276, 1606, 1443, 1141, 461, 586, 378, 1949, 0, 224, 552, 1828, 904, 804, 1040, 938, 821, 2006, 109, 304], [2005, 266, 213, 970, 1085, 1140, 1224, 1869, 554, 1495, 1256, 1662, 1671, 283, 281, 1432, 1107, 1460, 1535, 640, 755, 1295, 1764, 1638, 1929, 1592, 724, 1120, 1132, 728, 914, 930, 25, 1540, 689, 1661, 1814, 1974, 1594, 1634, 1954, 1322], [1672, 888, 1165, 368, 1940, 1662, 525, 1544, 1080, 1406, 637, 415, 159, 634, 309, 533, 608, 1102, 1054, 1297, 1460, 471, 1199, 613, 334, 1351, 1244, 333, 290, 395, 829, 1531, 565, 1405, 418, 1490, 279, 1690, 1435, 460, 729, 139], [49, 660, 1653, 4, 1984, 169, 1900, 437, 1182, 1834, 855, 335, 1494, 313, 1077, 776, 61, 1220, 593, 1938, 350, 1641, 295, 147, 335, 1894, 86, 639, 1958, 1730, 2021, 221, 1307, 1658, 103, 1697, 1900, 176, 1400, 1286, 271, 744], [856, 299, 1704, 1169, 1947, 426, 2020, 518, 218, 437, 731, 705, 33, 455, 1382, 270, 1512, 1120, 1425, 1225, 1360, 1071, 1092, 896, 1296, 1062, 1264, 396, 855, 1537, 1879, 173, 1567, 1548, 228, 897, 1534, 323, 744, 1564, 950, 20], [1309, 958, 2023, 811, 114, 1500, 77, 1031, 1204, 1811, 1178, 877, 1304, 308, 1898, 1763, 890, 1009, 631, 849, 1906, 376, 1214, 426, 171, 1096, 1157, 1704, 1060, 1332, 1811, 800, 712, 835, 169, 1598, 1948, 1384, 1143, 1209, 1431, 574], [1324, 725, 652, 99, 1910, 522, 871, 1609, 756, 1763, 1230, 1931, 487, 624, 1036, 1506, 114, 575, 800, 1054, 1027, 1309, 1506, 417, 1517, 270, 1610, 614, 219, 1512, 882, 1457, 1798, 1262, 655, 1271, 1066, 827, 1767, 1754, 1054, 345], [221, 1642, 258, 1504, 1569, 67, 57, 938, 1773, 218, 1635, 1514, 1038, 884, 1686, 508, 1050, 1104, 1121, 666, 887, 280, 1566, 384, 1328, 1336, 1906, 1477, 1969, 760, 447, 1887, 480, 92, 1959, 1917, 1132, 717, 741, 1876, 579, 132], [596, 286, 1471, 1206, 1778, 1982, 835, 566, 1347, 1842, 200, 675, 1659, 278, 1166, 172, 1985, 316, 724, 419, 1210, 800, 1637, 337, 218, 2020, 1207, 1992, 1339, 1096, 331, 836, 154, 854, 1242, 1069, 1290, 1428, 1024, 217, 350, 281], [1451, 1601, 1392, 472, 1165, 1190, 280, 653, 953, 350, 1309, 1981, 574, 1513, 1184, 2023, 1947, 591, 1745, 1305, 234, 1673, 2015, 1522, 187, 1921, 32, 1185, 29, 1394, 1297, 1880, 1381, 348, 622, 729, 1584, 813, 937, 808, 131, 1789], [1022, 1877, 831, 1567, 408, 1465, 1073, 1942, 1418, 268, 1267, 1806, 998, 6, 1366, 584, 92, 1137, 529, 659, 1085, 758, 2004, 384, 1099, 160, 998, 1311, 1914, 1002, 308, 1399, 1325, 2023, 1357, 23, 740, 223, 1865, 1, 2021, 1144], [101, 1226, 644, 128, 299, 631, 139, 55, 771, 409, 121, 609, 966, 823, 901, 556, 1396, 981, 365, 339, 1373, 154, 147, 1279, 1886, 1194, 1587, 311, 115, 1909, 1164, 1589, 1699, 1838, 1809, 1191, 536, 1686, 476, 390, 322, 1541], [874, 903, 917, 1557, 831, 1959, 1773, 930, 1513, 12, 1283, 156, 606, 10, 824, 1903, 1583, 752, 391, 73, 1733, 296, 1958, 1206, 989, 1151, 1123, 103, 1910, 1386, 940, 1522, 1883, 2009, 305, 1258, 134, 353, 49, 91, 1220, 124], [387, 1884, 286, 1704, 1453, 676, 543, 1445, 1130, 1136, 2010, 1428, 1146, 1190, 1355, 435, 1676, 1209, 139, 1614, 1758, 726, 1139, 1050, 372, 1877, 706, 1634, 881, 1067, 576, 1354, 260, 848, 821, 1390, 1754, 1117, 1449, 1683, 1949, 454], [441, 1929, 845, 2013, 618, 1070, 808, 836, 966, 401, 1437, 1209, 387, 1093, 1339, 1748, 190, 1947, 954, 1232, 1210, 1525, 724, 55, 980, 1943, 1107, 1053, 1791, 1514, 306, 8, 1344, 264, 140, 838, 802, 424, 1540, 1747, 891, 1020], [1048, 203, 1424, 469, 1786, 591, 1997, 1687, 539, 253, 278, 717, 1347, 1804, 279, 806, 912, 1837, 1566, 1135, 486, 1648, 1341, 1008, 637, 1699, 1396, 336, 1689, 330, 1033, 128, 1161, 1647, 669, 1788, 1711, 1980, 1882, 259, 138, 1467], [861, 228, 1485, 1832, 1658, 262, 1207, 719, 1982, 1108, 236, 92, 1894, 669, 437, 1976, 344, 2009, 1697, 874, 1486, 190, 1252, 1018, 561, 375, 1908, 45, 1934, 608, 1615, 658, 1234, 457, 409, 26, 1388, 1959, 1126, 656, 193, 507], [1324, 508, 1862, 1516, 693, 1819, 1583, 1472, 671, 1295, 1526, 1094, 518, 1189, 1583, 1345, 1054, 1788, 661, 960, 975, 927, 423, 380, 791, 1282, 1239, 756, 199, 1686, 745, 754, 1417, 1347, 1581, 626, 1772, 1465, 1985, 968, 1728, 1641], [1280, 392, 1695, 882, 1225, 1766, 683, 633, 1065, 1605, 1086, 500, 23, 1836, 583, 589, 1075, 810, 652, 1105, 511, 1756, 20, 756, 988, 1175, 134, 630, 320, 343, 213, 1885, 550, 146, 1121, 1650, 1101, 895, 294, 1710, 1995, 1022], [340, 1498, 491, 1964, 993, 1479, 1752, 263, 1156, 493, 1812, 1892, 595, 1919, 897, 1520, 1503, 1102, 809, 1374, 1693, 538, 1310, 372, 543, 245, 1912, 1193, 356, 14, 6, 1336, 821, 1111, 1678, 163, 298, 410, 740, 1039, 258, 1256], [542, 1181, 1683, 1782, 1355, 1598, 853, 1372, 1016, 1416, 466, 502, 528, 1428, 1742, 1748, 963, 1967, 844, 596, 996, 37, 201, 525, 147, 1576, 741, 532, 583, 192, 535, 762, 521, 198, 1204, 1460, 1848, 494, 1704, 43, 1437, 1946], [1308, 47, 975, 1577, 762, 1978, 0, 562, 1373, 1, 1046, 229, 542, 695, 582, 1455, 360, 245, 1343, 458, 1365, 1859, 1722, 1967, 19, 447, 1545, 1190, 1278, 675, 1992, 1769, 1435, 358, 10, 796, 155, 1000, 1615, 927, 1789, 823]]
[644, 915, 892, 1015, 1876, 1611, 925, 334, 36, 41, 629, 1829, 1939, 1681, 224, 646, 502, 1284, 663, 1592, 1890, 1097, 1499, 1927, 30, 1202, 2012, 985, 1393, 106, 1220, 1687, 1712, 1077, 1957, 1418, 555, 514, 1552, 968, 1645, 1850, 919, 587, 463, 963, 1503, 1251, 3, 1251, 1711, 114, 190, 1891, 740, 1358, 1698, 295, 1313, 1812, 1067, 455, 1622, 541, 155, 1083]
'''

这题为一道矩阵的运算,刚考完的线代可算是有点用了……

粗略看了一下代码,大致意思如下(K为加密矩阵,flag和c都可以视为一个列向量,等式两侧左乘逆向量即可):

1
2
3
4
5
6
def Cyber_key(LEN):
Key = [[] for i in range(row)]
for x in range(row):
for i in range(LEN):
Key[x].append(random.randint(0, 2023))
return Key

Cyber_key函数用随机数生成了加密矩阵,行数为row值66,列数为flag的长度,我用len函数测得flag长度为42。

1
2
3
4
5
6
7
8
9
def Punk_enc(Key, msg):
out = []
for l in Key:
s = 0
for x, y in zip(l, msg):
s += (x * y) % P
s %= P
out.append(s)
return out

Punk_enc函数进行了矩阵运算,zip函数把L的每一个值和msg的每一个值一一对应,注意到加密矩阵总共有66行,而flag只有42位,所以我们只需要s的前42位和对应的加密矩阵一起进行解密即可得到flag,s后面的24位又运算了小半轮,可以省略掉。

下面是官方给的wp,sage有关矩阵的操作还得继续研究:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#Sage
key=[[505, 469, 528, 1798, 373, 987, 981, 438, 1438, 1918, 768, 980, 720, 336, 1763, 585, 1582, 1020, 601, 1543, 1374, 1904, 340, 326, 947, 639, 1143, 371, 359, 953, 74, 657, 13, 359, 280, 1903, 687, 371, 114, 1232, 1573, 743], [1310, 205, 491, 137, 1743, 1185, 74, 1797, 867, 755, 967, 454, 800, 568, 625, 492, 1835, 1586, 1462, 619, 760, 1144, 98, 1764, 1356, 991, 1392, 816, 849, 259, 1305, 842, 1250, 1983, 1339, 752, 1170, 1976, 958, 1710, 1216, 1927], [1507, 1699, 1536, 1708, 739, 902, 1169, 1352, 886, 680, 1400, 1011, 132, 1561, 1001, 772, 1809, 208, 1161, 1691, 2015, 1099, 166, 1571, 551, 847, 663, 749, 1634, 1487, 960, 1675, 1017, 109, 63, 1714, 1540, 1515, 1382, 1569, 851, 985], [451, 1919, 680, 76, 707, 1283, 933, 658, 945, 1801, 352, 673, 1072, 48, 1994, 1923, 1685, 1684, 1374, 28, 1774, 1769, 1388, 1541, 604, 107, 1290, 787, 1622, 711, 323, 1846, 317, 1519, 1426, 123, 2015, 861, 544, 1401, 1869, 1833], [862, 1316, 393, 1190, 2012, 687, 78, 61, 1391, 1238, 1282, 866, 1385, 1200, 292, 1702, 1599, 712, 1108, 653, 1711, 745, 100, 275, 322, 1671, 1723, 895, 661, 1726, 497, 342, 1010, 47, 1204, 1911, 1734, 1567, 1892, 954, 386, 1996], [1333, 1928, 191, 1502, 1106, 579, 779, 512, 313, 308, 1277, 1547, 1814, 1434, 1867, 670, 543, 404, 1570, 179, 555, 1896, 289, 492, 1874, 1190, 1885, 748, 1375, 401, 1685, 618, 1614, 288, 2017, 571, 670, 873, 98, 563, 180, 749], [262, 1072, 1188, 864, 960, 1069, 1931, 870, 573, 44, 38, 1525, 41, 1197, 1618, 857, 187, 804, 1828, 1525, 96, 204, 1565, 419, 1397, 1487, 1902, 1150, 650, 1562, 151, 564, 1836, 826, 95, 158, 495, 1357, 2005, 819, 783, 880], [636, 985, 809, 1165, 1478, 998, 408, 1897, 988, 421, 743, 1210, 1128, 1901, 943, 512, 1587, 1784, 911, 857, 434, 367, 1345, 104, 143, 357, 426, 1169, 1876, 1111, 1355, 371, 219, 1056, 432, 780, 1798, 151, 210, 1293, 807, 620], [29, 440, 1323, 1960, 1791, 1084, 777, 1314, 709, 1014, 1721, 108, 3, 961, 1253, 245, 862, 1899, 1519, 563, 347, 870, 820, 1787, 1323, 1113, 150, 1108, 1547, 1438, 845, 788, 1221, 1680, 795, 923, 1308, 1114, 153, 1985, 573, 132], [1979, 1831, 1374, 601, 1736, 1778, 1390, 138, 1295, 1582, 1777, 362, 647, 753, 627, 142, 1732, 994, 1911, 227, 1069, 1943, 1206, 1266, 1605, 827, 1153, 1375, 486, 1222, 1938, 794, 909, 629, 1232, 756, 935, 1374, 1148, 1312, 584, 901], [631, 136, 1835, 686, 1779, 1298, 1471, 1009, 107, 906, 4, 201, 859, 1808, 1743, 1286, 305, 266, 1374, 992, 531, 389, 1482, 362, 873, 533, 341, 1357, 85, 424, 207, 995, 275, 857, 1239, 770, 1355, 516, 178, 1560, 228, 1843], [1863, 1423, 786, 209, 1565, 1735, 1662, 1571, 749, 326, 1258, 1099, 1780, 1240, 865, 810, 7, 301, 1926, 692, 67, 978, 1172, 641, 839, 505, 1106, 423, 827, 1838, 388, 1749, 483, 880, 454, 773, 1961, 1153, 858, 963, 92, 829], [2009, 66, 520, 1027, 1804, 882, 42, 1826, 1732, 1093, 78, 1826, 1948, 734, 1486, 1285, 28, 1092, 174, 292, 1412, 24, 1454, 1015, 1560, 1154, 1168, 704, 1224, 1422, 784, 1353, 799, 1591, 613, 1318, 1623, 1151, 968, 297, 953, 1178], [1889, 727, 1189, 160, 1198, 1338, 970, 168, 1737, 1356, 1525, 590, 1773, 1397, 105, 1368, 401, 1569, 287, 1757, 801, 1818, 309, 1416, 1721, 1403, 1086, 583, 1203, 172, 1030, 647, 1497, 1222, 1581, 432, 1199, 1279, 5, 570, 556, 1936], [1514, 1162, 130, 1023, 538, 1772, 1525, 1709, 774, 1904, 1489, 837, 742, 797, 446, 1240, 847, 624, 1629, 2011, 867, 1097, 1814, 231, 381, 46, 363, 1560, 786, 1706, 800, 112, 748, 745, 407, 1290, 1093, 1268, 1536, 129, 1632, 1200], [698, 1238, 1100, 591, 1166, 1320, 620, 1044, 984, 744, 453, 1927, 1019, 1488, 1586, 1428, 412, 42, 776, 548, 2006, 409, 1767, 506, 1153, 1398, 391, 1597, 1794, 1203, 1034, 180, 433, 989, 1308, 1342, 1041, 1461, 782, 1284, 225, 492], [342, 15, 324, 551, 329, 1427, 186, 932, 774, 275, 311, 1562, 1557, 455, 329, 66, 0, 856, 792, 849, 878, 1362, 304, 1004, 1093, 1768, 793, 366, 965, 932, 1548, 759, 990, 1033, 720, 1344, 1438, 481, 1546, 985, 51, 1915], [1737, 1934, 1414, 131, 1328, 919, 569, 1731, 1771, 43, 1622, 322, 2000, 1918, 384, 995, 1282, 1380, 449, 1566, 1981, 286, 981, 704, 640, 551, 5, 1019, 598, 1079, 1150, 209, 464, 1555, 2, 1988, 1305, 127, 152, 701, 553, 1030], [817, 176, 737, 657, 1507, 514, 1453, 1656, 1229, 315, 368, 332, 460, 933, 1553, 1409, 1137, 1910, 209, 1906, 1487, 571, 996, 1489, 2011, 245, 1510, 115, 1155, 349, 67, 620, 759, 699, 1034, 1030, 984, 70, 1585, 1580, 121, 2], [526, 1875, 273, 1552, 641, 532, 613, 1092, 72, 1518, 600, 1380, 1088, 1371, 143, 1764, 1695, 1747, 1693, 2006, 614, 305, 1784, 1474, 1761, 730, 1968, 1803, 520, 917, 1976, 838, 525, 1769, 2005, 1625, 128, 728, 1729, 440, 288, 1530], [17, 1580, 403, 1813, 1514, 1603, 559, 1845, 408, 1942, 966, 1393, 544, 272, 1400, 1940, 412, 1968, 837, 945, 503, 409, 154, 264, 379, 218, 1847, 966, 1103, 125, 1935, 1381, 1552, 126, 1379, 397, 735, 1165, 162, 1696, 44, 238], [1401, 75, 99, 633, 922, 1093, 831, 1422, 1489, 46, 728, 1191, 292, 473, 640, 423, 766, 1991, 1561, 1897, 583, 385, 409, 1814, 1684, 879, 1414, 160, 1870, 577, 1394, 1088, 1248, 1425, 405, 1726, 77, 726, 1070, 642, 935, 1105], [1156, 765, 913, 323, 888, 727, 1826, 744, 54, 1009, 1790, 185, 1498, 1599, 1069, 62, 59, 32, 1280, 274, 728, 1831, 1879, 175, 708, 1466, 589, 263, 707, 1542, 1790, 1816, 1854, 992, 1402, 1354, 1501, 1200, 1653, 1067, 1756, 573], [645, 378, 356, 1474, 837, 1664, 45, 259, 289, 231, 1640, 244, 1864, 1022, 741, 1741, 1594, 1353, 991, 2002, 1969, 1522, 1852, 1031, 1296, 347, 1005, 1506, 760, 630, 462, 1302, 454, 466, 163, 488, 1239, 1554, 1482, 1918, 1394, 1244], [199, 1336, 969, 526, 2009, 801, 1762, 1185, 645, 1577, 1303, 707, 1731, 1212, 341, 121, 1984, 1108, 1794, 1078, 404, 248, 36, 42, 1757, 1051, 1485, 1542, 442, 666, 1596, 335, 1527, 1707, 1035, 1924, 386, 1566, 1509, 998, 977, 328], [1802, 1664, 1315, 607, 95, 477, 1534, 834, 1199, 1330, 738, 1339, 1313, 294, 1860, 1693, 2014, 1663, 549, 298, 1076, 618, 59, 749, 995, 1369, 558, 1703, 656, 1745, 1813, 1428, 612, 12, 624, 111, 850, 456, 596, 817, 383, 630], [221, 207, 1253, 1353, 992, 1732, 1038, 325, 1696, 662, 771, 1437, 1616, 396, 1568, 476, 232, 220, 1945, 1500, 1865, 1477, 1540, 1608, 823, 255, 342, 1912, 733, 1450, 1600, 1838, 69, 32, 1392, 1647, 820, 492, 1479, 1172, 993, 1412], [1207, 930, 69, 289, 1770, 162, 1442, 1071, 1598, 1900, 1409, 433, 1248, 1668, 314, 1201, 425, 334, 1373, 789, 975, 177, 1526, 49, 29, 174, 885, 264, 437, 287, 167, 1332, 1870, 1330, 1789, 372, 140, 1697, 1018, 642, 1894, 1829], [1710, 1301, 511, 1837, 116, 1749, 1727, 1479, 950, 951, 1104, 866, 838, 1248, 911, 988, 1275, 637, 1636, 250, 1603, 1783, 1821, 149, 388, 1474, 1366, 1788, 1038, 4, 201, 1003, 1246, 1914, 233, 1625, 1041, 1979, 649, 665, 1381, 1522], [855, 35, 317, 97, 400, 800, 107, 91, 1444, 1063, 552, 1363, 600, 767, 1313, 1117, 769, 541, 1466, 848, 935, 1918, 555, 1218, 1750, 1953, 1103, 1969, 1289, 634, 1310, 182, 1071, 1959, 544, 462, 377, 1696, 1597, 1936, 1285, 367], [598, 1990, 750, 584, 227, 1392, 1493, 748, 1671, 224, 1360, 1094, 1994, 1792, 1140, 779, 1939, 361, 289, 1235, 213, 517, 1485, 1390, 804, 132, 920, 536, 1235, 837, 298, 1139, 961, 1521, 431, 76, 2019, 884, 1991, 522, 342, 1609], [114, 1608, 1127, 722, 97, 140, 218, 617, 475, 1680, 214, 1595, 1373, 2021, 1031, 1243, 1526, 1562, 134, 684, 1178, 951, 1470, 1293, 1562, 744, 424, 336, 932, 897, 42, 1968, 1144, 195, 686, 46, 1032, 230, 1285, 132, 1514, 169], [1870, 622, 830, 283, 713, 1893, 270, 573, 732, 1233, 246, 1408, 1890, 119, 1529, 396, 1522, 486, 1371, 211, 1196, 671, 200, 1390, 1790, 547, 567, 1315, 1782, 1661, 756, 6, 1864, 626, 1318, 694, 1632, 1177, 1128, 1327, 405, 1283], [1714, 277, 1154, 369, 1472, 417, 541, 1244, 638, 1332, 512, 492, 1272, 929, 551, 34, 954, 362, 75, 1009, 725, 1481, 952, 1297, 1612, 289, 1684, 817, 112, 1731, 837, 1820, 1457, 1411, 1836, 454, 1984, 178, 46, 552, 282, 720], [1602, 921, 919, 637, 25, 1052, 1246, 831, 1332, 1664, 260, 1387, 1660, 19, 839, 844, 1934, 1606, 970, 539, 992, 1401, 1804, 1879, 297, 1325, 1671, 128, 667, 1169, 808, 1238, 366, 1409, 1369, 1997, 1775, 1586, 746, 278, 1134, 464], [1441, 1529, 415, 494, 1784, 1042, 799, 1701, 985, 404, 734, 1123, 1206, 1493, 1446, 562, 161, 1737, 1943, 753, 1782, 1341, 794, 333, 891, 973, 1656, 1995, 228, 523, 882, 228, 1010, 212, 262, 1948, 1573, 104, 767, 1607, 1333, 650], [918, 1741, 1195, 247, 2001, 1290, 1640, 1655, 1209, 1171, 1686, 1565, 1347, 1245, 350, 1234, 1271, 724, 213, 1994, 974, 677, 415, 1728, 1465, 222, 425, 616, 1649, 1114, 285, 753, 593, 1795, 552, 192, 247, 1286, 1995, 304, 402, 240], [1870, 843, 803, 905, 1256, 1668, 1850, 592, 1745, 1551, 957, 1095, 1492, 1413, 1604, 1944, 1424, 543, 169, 1811, 240, 996, 524, 556, 1189, 746, 1166, 157, 303, 965, 1848, 472, 1559, 419, 932, 2022, 966, 943, 1507, 1126, 1179, 1316], [1984, 296, 1135, 779, 530, 1212, 1122, 113, 805, 108, 990, 897, 1372, 774, 940, 633, 999, 1113, 873, 1933, 233, 236, 1006, 1767, 1575, 736, 1530, 843, 1373, 526, 1863, 2022, 189, 291, 1746, 1804, 769, 1355, 1745, 1355, 368, 666], [1714, 1278, 333, 2002, 379, 1788, 75, 174, 1369, 376, 1881, 553, 928, 1269, 1930, 622, 223, 278, 528, 1001, 918, 1018, 903, 1133, 420, 1389, 1796, 488, 410, 481, 1499, 228, 811, 1539, 91, 499, 1715, 249, 809, 1040, 1862, 1284], [560, 156, 1508, 1302, 194, 1062, 49, 1000, 1670, 1094, 1565, 1982, 1848, 204, 1846, 1565, 186, 1701, 1233, 855, 555, 938, 1489, 945, 1205, 1036, 1093, 47, 416, 1832, 173, 801, 684, 10, 1729, 1931, 27, 461, 1619, 1468, 1069, 1455], [270, 476, 948, 1474, 1209, 1968, 1193, 1683, 223, 1220, 730, 1122, 825, 1479, 922, 1684, 1526, 1532, 474, 1444, 1509, 1176, 1069, 1505, 1024, 1845, 1114, 762, 428, 893, 2012, 182, 1288, 851, 780, 228, 1393, 1834, 314, 402, 349, 189], [1677, 1049, 606, 1404, 1606, 164, 251, 1134, 893, 834, 680, 1260, 1428, 1743, 1658, 298, 705, 1450, 1064, 207, 787, 1094, 545, 559, 131, 1110, 1402, 1671, 545, 1885, 241, 525, 1333, 268, 710, 1602, 925, 1713, 1390, 458, 292, 1982], [1928, 173, 1894, 177, 1485, 2019, 1602, 1975, 1394, 813, 695, 998, 451, 859, 1913, 1307, 1200, 1900, 193, 1288, 509, 1568, 1664, 698, 1737, 1310, 1582, 634, 630, 1773, 315, 1225, 955, 195, 364, 1952, 1514, 107, 1103, 851, 194, 782], [264, 1210, 1424, 774, 1867, 33, 1584, 76, 1170, 1217, 1404, 218, 419, 1478, 1780, 600, 480, 1559, 1687, 418, 963, 164, 1276, 1606, 1443, 1141, 461, 586, 378, 1949, 0, 224, 552, 1828, 904, 804, 1040, 938, 821, 2006, 109, 304], [2005, 266, 213, 970, 1085, 1140, 1224, 1869, 554, 1495, 1256, 1662, 1671, 283, 281, 1432, 1107, 1460, 1535, 640, 755, 1295, 1764, 1638, 1929, 1592, 724, 1120, 1132, 728, 914, 930, 25, 1540, 689, 1661, 1814, 1974, 1594, 1634, 1954, 1322], [1672, 888, 1165, 368, 1940, 1662, 525, 1544, 1080, 1406, 637, 415, 159, 634, 309, 533, 608, 1102, 1054, 1297, 1460, 471, 1199, 613, 334, 1351, 1244, 333, 290, 395, 829, 1531, 565, 1405, 418, 1490, 279, 1690, 1435, 460, 729, 139], [49, 660, 1653, 4, 1984, 169, 1900, 437, 1182, 1834, 855, 335, 1494, 313, 1077, 776, 61, 1220, 593, 1938, 350, 1641, 295, 147, 335, 1894, 86, 639, 1958, 1730, 2021, 221, 1307, 1658, 103, 1697, 1900, 176, 1400, 1286, 271, 744], [856, 299, 1704, 1169, 1947, 426, 2020, 518, 218, 437, 731, 705, 33, 455, 1382, 270, 1512, 1120, 1425, 1225, 1360, 1071, 1092, 896, 1296, 1062, 1264, 396, 855, 1537, 1879, 173, 1567, 1548, 228, 897, 1534, 323, 744, 1564, 950, 20], [1309, 958, 2023, 811, 114, 1500, 77, 1031, 1204, 1811, 1178, 877, 1304, 308, 1898, 1763, 890, 1009, 631, 849, 1906, 376, 1214, 426, 171, 1096, 1157, 1704, 1060, 1332, 1811, 800, 712, 835, 169, 1598, 1948, 1384, 1143, 1209, 1431, 574], [1324, 725, 652, 99, 1910, 522, 871, 1609, 756, 1763, 1230, 1931, 487, 624, 1036, 1506, 114, 575, 800, 1054, 1027, 1309, 1506, 417, 1517, 270, 1610, 614, 219, 1512, 882, 1457, 1798, 1262, 655, 1271, 1066, 827, 1767, 1754, 1054, 345], [221, 1642, 258, 1504, 1569, 67, 57, 938, 1773, 218, 1635, 1514, 1038, 884, 1686, 508, 1050, 1104, 1121, 666, 887, 280, 1566, 384, 1328, 1336, 1906, 1477, 1969, 760, 447, 1887, 480, 92, 1959, 1917, 1132, 717, 741, 1876, 579, 132], [596, 286, 1471, 1206, 1778, 1982, 835, 566, 1347, 1842, 200, 675, 1659, 278, 1166, 172, 1985, 316, 724, 419, 1210, 800, 1637, 337, 218, 2020, 1207, 1992, 1339, 1096, 331, 836, 154, 854, 1242, 1069, 1290, 1428, 1024, 217, 350, 281], [1451, 1601, 1392, 472, 1165, 1190, 280, 653, 953, 350, 1309, 1981, 574, 1513, 1184, 2023, 1947, 591, 1745, 1305, 234, 1673, 2015, 1522, 187, 1921, 32, 1185, 29, 1394, 1297, 1880, 1381, 348, 622, 729, 1584, 813, 937, 808, 131, 1789], [1022, 1877, 831, 1567, 408, 1465, 1073, 1942, 1418, 268, 1267, 1806, 998, 6, 1366, 584, 92, 1137, 529, 659, 1085, 758, 2004, 384, 1099, 160, 998, 1311, 1914, 1002, 308, 1399, 1325, 2023, 1357, 23, 740, 223, 1865, 1, 2021, 1144], [101, 1226, 644, 128, 299, 631, 139, 55, 771, 409, 121, 609, 966, 823, 901, 556, 1396, 981, 365, 339, 1373, 154, 147, 1279, 1886, 1194, 1587, 311, 115, 1909, 1164, 1589, 1699, 1838, 1809, 1191, 536, 1686, 476, 390, 322, 1541], [874, 903, 917, 1557, 831, 1959, 1773, 930, 1513, 12, 1283, 156, 606, 10, 824, 1903, 1583, 752, 391, 73, 1733, 296, 1958, 1206, 989, 1151, 1123, 103, 1910, 1386, 940, 1522, 1883, 2009, 305, 1258, 134, 353, 49, 91, 1220, 124], [387, 1884, 286, 1704, 1453, 676, 543, 1445, 1130, 1136, 2010, 1428, 1146, 1190, 1355, 435, 1676, 1209, 139, 1614, 1758, 726, 1139, 1050, 372, 1877, 706, 1634, 881, 1067, 576, 1354, 260, 848, 821, 1390, 1754, 1117, 1449, 1683, 1949, 454], [441, 1929, 845, 2013, 618, 1070, 808, 836, 966, 401, 1437, 1209, 387, 1093, 1339, 1748, 190, 1947, 954, 1232, 1210, 1525, 724, 55, 980, 1943, 1107, 1053, 1791, 1514, 306, 8, 1344, 264, 140, 838, 802, 424, 1540, 1747, 891, 1020], [1048, 203, 1424, 469, 1786, 591, 1997, 1687, 539, 253, 278, 717, 1347, 1804, 279, 806, 912, 1837, 1566, 1135, 486, 1648, 1341, 1008, 637, 1699, 1396, 336, 1689, 330, 1033, 128, 1161, 1647, 669, 1788, 1711, 1980, 1882, 259, 138, 1467], [861, 228, 1485, 1832, 1658, 262, 1207, 719, 1982, 1108, 236, 92, 1894, 669, 437, 1976, 344, 2009, 1697, 874, 1486, 190, 1252, 1018, 561, 375, 1908, 45, 1934, 608, 1615, 658, 1234, 457, 409, 26, 1388, 1959, 1126, 656, 193, 507], [1324, 508, 1862, 1516, 693, 1819, 1583, 1472, 671, 1295, 1526, 1094, 518, 1189, 1583, 1345, 1054, 1788, 661, 960, 975, 927, 423, 380, 791, 1282, 1239, 756, 199, 1686, 745, 754, 1417, 1347, 1581, 626, 1772, 1465, 1985, 968, 1728, 1641], [1280, 392, 1695, 882, 1225, 1766, 683, 633, 1065, 1605, 1086, 500, 23, 1836, 583, 589, 1075, 810, 652, 1105, 511, 1756, 20, 756, 988, 1175, 134, 630, 320, 343, 213, 1885, 550, 146, 1121, 1650, 1101, 895, 294, 1710, 1995, 1022], [340, 1498, 491, 1964, 993, 1479, 1752, 263, 1156, 493, 1812, 1892, 595, 1919, 897, 1520, 1503, 1102, 809, 1374, 1693, 538, 1310, 372, 543, 245, 1912, 1193, 356, 14, 6, 1336, 821, 1111, 1678, 163, 298, 410, 740, 1039, 258, 1256], [542, 1181, 1683, 1782, 1355, 1598, 853, 1372, 1016, 1416, 466, 502, 528, 1428, 1742, 1748, 963, 1967, 844, 596, 996, 37, 201, 525, 147, 1576, 741, 532, 583, 192, 535, 762, 521, 198, 1204, 1460, 1848, 494, 1704, 43, 1437, 1946], [1308, 47, 975, 1577, 762, 1978, 0, 562, 1373, 1, 1046, 229, 542, 695, 582, 1455, 360, 245, 1343, 458, 1365, 1859, 1722, 1967, 19, 447, 1545, 1190, 1278, 675, 1992, 1769, 1435, 358, 10, 796, 155, 1000, 1615, 927, 1789, 823]]
c=[644, 915, 892, 1015, 1876, 1611, 925, 334, 36, 41, 629, 1829, 1939, 1681, 224, 646, 502, 1284, 663, 1592, 1890, 1097, 1499, 1927, 30, 1202, 2012, 985, 1393, 106, 1220, 1687, 1712, 1077, 1957, 1418, 555, 514, 1552, 968, 1645, 1850, 919, 587, 463, 963, 1503, 1251, 3, 1251, 1711, 114, 190, 1891, 740, 1358, 1698, 295, 1313, 1812, 1067, 455, 1622, 541, 155, 1083]
flag_len = len(key[0])
P = 2048
K = matrix(Zmod(P), key[:flag_len])
C = vector(Zmod(P), c[:flag_len])
m = K.inverse() * C #inverse求逆矩阵
print(m)
flag = ''
for i in m:
flag += chr(i)
print(flag)
#flag{0e3ceb92-ef28-48ff-8a1f-556ea8e96263}

RRRRRRSA

题目:

1
2
3
4
5
6
7
8
9
10
11
from secret import flag
from Crypto.Util.number import *

e = 321
m = bytes_to_long(flag)
p = getPrime(512)
q = getPrime(512)
n = p*q
c = pow(m, e, n)
print(n)
print(c)

给了nc的IP和的端口,我们可以通过nc来获得所得的一组n和c。

我们每次nc所得到的n和c值都是不同的,这样我们可以通过不断访问得到多组值,这就需要用CRT。那么需要多少组数据呢?把这道题看做是低指数广播攻击的话,不难发现我们需要e组数据:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import gmpy2
from pwn import *
from libnum import *
from Crypto.Util.number import *

e=321
ns,cs = [],[]
for i in range(321):
print(f'{i+1}/{321}')
sh = remote('81.68.77.181', 2023)
ns.append(int(sh.recvline().decode()))
cs.append(int(sh.recvline().decode()))
m_e=solve_crt(cs,ns)
m = int(gmpy2.iroot(m_e, e)[0])
print(long_to_bytes(m))

EasyLock

题目:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from secret import flag
from Crypto.Util.number import *

m = bytes_to_long(flag)
assert m.bit_length() == 47
data = [2, 3, 4, 5, 6]
cs = []
p = getPrime(512)
q = getPrime(512)
n = p*q
for i in data:
cs.append(pow(i, m, n))
print(cs)

"""
[183098212086317720236828757315510192339273033804875740822801041376722387458993552796227899411901966324318366514880536763913315608412750265815750386810801443666072579873995967676472994916617708760086271155827496223499121301339946900578686321571238854410077055150282805741312173826325669295346629270100887114, 57033027040944100515577298747833062983449034346155581535109171399667991971614122726451624246276583123688811765412755210627513537740891720491136798691017567675611749056264437247135506921747135448387155606513983563110678466501221603978172670533058510913876368172674768929417846635764813733749021238273031358064, 44177513422937659688192503808032734159830361147993789424022745838993946766432456884886189398779755202878679629523667923807343226973440318127947558457476925179848208108399587026072741947465486816791306581859876197942191253278120326733144030253277598039138046967591357892542649422324554104602547660747339872074, 12631302718057472129138289484187738038805661685759196779990368768599115569927115234126312113575785471158626604808250556471019475882601443785660157133230999298014824293609691681149195181799904358979944719852988436666306120350671288382565369084160416022015445829639878167524217607450918100132212115997395372780, 42899381454706854217031716361682990989382003331688973566655317536112884234898037025883907894505663567670829738793956574655657437562098921910867502135260835097785409348930680677890714703165271668372795217905436049326872168290466249129739381681341323649536725632009485619857375114283009023943744880775769510652]
"""

给了模数用2,3,4,5,6计算得到的c,可以计算求得n的倍数项:

将上面两式提取公因式,得到n,注意这里并不确定得到的n是否还有系数,可以将n改为二进制看看位数是否满足1024位。

现在我们得到了n,又有:

m为47位,现在相当于求解离散对数,试了试在线计算器发现解不出来,wp借助了sage:

1
2
3
4
5
6
7
8
9
10
from Crypto.Util.number import *

c2,c3,c4,c5,c6 = [183098212086317720236828757315510192339273033804875740822801041376722387458993552796227899411901966324318366514880536763913315608412750265815750386810801443666072579873995967676472994916617708760086271155827496223499121301339946900578686321571238854410077055150282805741312173826325669295346629270100887114,
57033027040944100515577298747833062983449034346155581535109171399667991971614122726451624246276583123688811765412755210627513537740891720491136798691017567675611749056264437247135506921747135448387155606513983563110678466501221603978172670533058510913876368172674768929417846635764813733749021238273031358064,
44177513422937659688192503808032734159830361147993789424022745838993946766432456884886189398779755202878679629523667923807343226973440318127947558457476925179848208108399587026072741947465486816791306581859876197942191253278120326733144030253277598039138046967591357892542649422324554104602547660747339872074,
12631302718057472129138289484187738038805661685759196779990368768599115569927115234126312113575785471158626604808250556471019475882601443785660157133230999298014824293609691681149195181799904358979944719852988436666306120350671288382565369084160416022015445829639878167524217607450918100132212115997395372780,
42899381454706854217031716361682990989382003331688973566655317536112884234898037025883907894505663567670829738793956574655657437562098921910867502135260835097785409348930680677890714703165271668372795217905436049326872168290466249129739381681341323649536725632009485619857375114283009023943744880775769510652]
n = gcd(c2**2-c4, c2*c3-c6)
m = discrete_log_lambda(Mod(c2,n), Mod(2, n), bounds=(2^46, 2^47))
print(b'flag{' + long_to_bytes(int(m)) + b'}')

discrete_log_lambda函数用法(求解以base为底、a的对数,已知flag位数确定bound):

1
discrete_log_lambda(a,base,bound)