n = 44571911854174527304485400947383944661319242813524818888269963870884859557542264803774212076803157466539443358890313286282067621989609252352994203884813364011659788234277369629312571477760818634118449563652776213438461157699447304292906151410018017960605868035069246651843561595572415595568705784173761441087845248621463389786351743200696279604003824362262237505386409700329605140703782099240992158439201646344692107831931849079888757310523663310273856448713786678014221779214444879454790399990056124051739535141631564534546955444505648933134838799753362350266884682987713823886338789502396879543498267617432600351655901149380496067582237899323865338094444822339890783781705936546257971766978222763417870606459677496796373799679580683317833001077683871698246143179166277232084089913202832193540581401453311842960318036078745448783370048914350299341586452159634173821890439194014264891549345881324015485910286021846721593668473 c = 11212699652154912414419576042130573737460880175860430868241856564678915039929479534373946033032215673944727767507831028500814261134142245577246925294110977629353584372842303558820509861245550773062016272543030477733653059813274587939179134498599049035104941393508776333632172797303569396612594631646093552388772109708942113683783815011735472088985078464550997064595366458370527490791625688389950370254858619018250060982532954113416688720602160768503752410505420577683484807166966007396618297253478916176712265476128018816694458551219452105277131141962052020824990732525958682439071443399050470856132519918853636638476540689226313542250551212688215822543717035669764276377536087788514506366740244284790716170847347643593400673746020474777085815046098314460862593936684624708574116108322520985637474375038848494466480630236867228454838428542365166285156741433845949358227546683144341695680712263215773807461091898003011630162481 p3 = 891438237083490546089708018947678893226384856270496377765399277417697191150845296075484241536063149330788867177806265725641352439792185047059884077696267280233195764685547392586251429555216372682368991273055524268769223153988946085858123028200360359212117360701384933036871231911448311911374115683475228820531478240539549424647154342506853356292956506486091063660095505979187297020928573605860329881982122478494944846700224611808246427660214535971723459345029873385956677292979041143593821672034573140001092625650099257402018634684516092489263998517027205660003413512870074652126328536906790020794659204007921147300771594986038917179253827432120018857213350120695302091483756021206199805521083496979628811676116525321724267588515105188480380865374667274442027086789352802613365511142499668793725505110436809024171752137883546327359935102833441492430652019931999144063825010678766130335038975376834579129516127516820037383067 q3 = 44571911854174527304485400947383944661319242813524818888269963870884859557542264803774212076803157466539443358890313286282067621989609252352994203884813364011659788234277369629312571477760818634118449563652776213438461157699447304292906151410018017960605868035069246651843561595572415595568705784173761440671033435053531971051698504592848580356684103015611323747688216493729331061402058160819388999663041629882482138465124920580049057123360829897432472221079140360215664537272316836767039948368780837985855835419681893347839311156887660438769948501100287062738217966360434291369179859862550767272985972263442512061098317471708987686120577904202391381040801620069987103931326500146536990700234262413595295698193570184681785854277656410199477649697026112650581343325348837547631237627207304757407395388155701341044939408589591213693329516396531103489233367665983149963665364824119870832353269655933102900004362236232825539480774 r3 = 22285955927087263652242700473691972330659621406762409444134981935442429778771132401887106038401578733269721679445156643141033810994804626176497101942406682005829894117138684814656285738880409317059224781826388106719230578849723652146453075705009008980302934017534623325921780797786207797784352892086880720749202442492937918619992591614713131681306874944356693778359565004415437554407990089293135634916859631279984463829118336826115430997439527110961309956466956650522900331263720500751112297418506140413317489683875995326726992533904683800042127871963320754241310699432792081707870167598822650064976439270556418985242630368723264289700246406905189810458354474959276748887369363592834205660349184660073395182450526542246354364903399132116153732074081050985584216815493617906868615192465631416955706457835185743023758573279838341229835613609332206338401219168119635681832981552328638132500079074010106995297184587143613134093145
p = gmpy2.iroot(p3,3)[0] i = 0 whileTrue: r = p * 5 + i if isPrime(r): i = 0 break else: i += 1 whileTrue: q = p * 10 + i if isPrime(q): break else: i += 1
phi = (p-1)*(q-1)*(r-1) d = gmpy2.invert(65537,phi) m = pow(c,d,n) print(long_to_bytes(m)) # NSSCTF{cc10786a-cc59-a07d-5c9f-df1c55b18cd4}
from random import randint from secret import flag, enc_key
dir = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}" assertlen(flag) == 64 assertlen(enc_key) == 64
defgetGraph(row, column): graph = [[''for _ inrange(row)] for _ inrange(column)] for i inrange(column): for j inrange(row): graph[i][j] = dir[randint(0, 63)] return graph
defbestkasscnEncryption(str): binary = '' res = '' for c instr: binary += '0' + bin(ord(c))[2:] + '' whilelen(binary) % 6 != 0: binary += '0' for i inrange(len(binary) // 6): res += dir[int(binary[i * 6:6 + i * 6], 2)] whilelen(res) % 3 != 0: res += '}' return res
encrypt = bestkasscnEncryption(enc_key)
graph1 = getGraph(len(encrypt), len(encrypt)) graph2 = getGraph(len(encrypt), len(encrypt)) for i inrange(len(flag)): graph1[dir.index(encrypt[i])][i] = enc_key[i] graph2[i][dir.index(encrypt[i])] = flag[i]
for i inrange(0, len(flag), 2): graph2[i][dir.index(encrypt[i])] = enc_key[i] graph1[dir.index(encrypt[i])][i] = flag[i]
withopen('graph1.txt', 'w') as file: file.write("graph1:\n") for i in graph1: file.write(str(i)) file.write(',') file.write('\n') file.close() withopen('graph2.txt', 'w') as file: file.write("graph2:\n") for j in graph2: file.write(str(j)) file.write(',') file.write('\n') file.close()
withopen('encrypt.txt', 'w') as file: file.write(encrypt) file.close()
注意到
1 2 3 4 5 6 7
for i inrange(len(flag)): graph1[dir.index(encrypt[i])][i] = enc_key[i] graph2[i][dir.index(encrypt[i])] = flag[i]
for i inrange(0, len(flag), 2): graph2[i][dir.index(encrypt[i])] = enc_key[i] graph1[dir.index(encrypt[i])][i] = flag[i]
dir = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}" encrypt = "t25Lx3DOB19OyxnFC2vLBL90AgvFB2nLyw5FDgHPBMTZx25VDgHPBMDFB2zFBwvYzv9YAxzLCNnFC29Fzg9Fsq}"
graph1 = [[...]] graph2 = [[...]]
for i inrange(64): if i % 2 == 0: m = graph1[dir.index(encrypt[i])][i] flag += m else: m = graph2[i][dir.index(encrypt[i])] flag += m print(flag) # One_who_has_seen_the_ocean_thinks_nothing_of_mere_rivers_so_do_I # NSSCTF{What_I_miss_is_saying_nothing_nothing_better_than_hotpot}
defcompare(str1,str2): #计算相似度 assertlen(str1) == len(str2) num = 0 for i inrange(len(str1)): if str1[i] == str2[i]: num += 1 if (num / len(str1)) > 0.75: returnTrue else: returnFalse table = "0123456789" prefix = [] for i in table: temp = bin(ord(i) // 2)[2:].zfill(7) if temp notin prefix: prefix.append(temp) # 把这些字符2进制形式的高7位存入
key_may = [] for i in tqdm(product(prefix,repeat = 8)): #爆破key1和key3,长度为八个字节 temp = "".join(j + "0"for j inlist(i)) key = long_to_bytes(int(temp,2)) # 开始爆 des1 = DES.new(key,DES.MODE_ECB) seed = b"!NSSCTF!" output1 = "" for j inrange(200): seed = des1.encrypt(seed) out = str(bytes_to_long(seed) & 1) output1 += out if compare(output1,output[:200]): key_may.append(key)
definit(self,para_len,p): self.p = p self.b = randint(1, self.p) self.a = [randint(1, self.p) for i inrange(para_len)] self.s = [ord(choice(string.printable)) for i inrange(para_len)] defget_params(self): return [self.a,self.b,self.s[0]]
flag = bytes_to_long(flag) flag_bin = bin(flag)[2:]
Round = 2024 A_len = 10 p = getPrime(256)
output = [] for i in flag_bin: if(i == "0"): temp = MRG(A_len,p) for j inrange(Round): temp.next() output.append(temp.get_params()) else: a = [randint(1,p) for i inrange(A_len)] b = randint(1,p) s = randint(1,p) output.append([a,b,s])
withopen("output.txt","w") as f: f.write(str(p)) f.write(str(output))
m = "" for j in trange(len(output)): temp = output[j] a = temp[0] a.append(1) b = temp[1] s2024 = temp[2] Ge = Matrix(Zmod(p),11,11) #很值得注意,这个矩阵的定义域是mod p for i inrange(9): Ge[i,i+1] = 1 Ge[-2,i] = a[i] Ge[-2,-2] = a[-2] Ge[-2,-1] = b Ge[-1,-1] = 1 L = Ge^2024 L1 = vector(ZZ,L.transpose()[:,0].list()) #提取转置矩阵的第一列 M = Matrix(ZZ,13,13) for i inrange(11): M[i,i] = 1 M[i,-1] = L1[i] M[-2,-2] = 1 M[-2,-1] = -s2024 M[-1,-1] = p Q = diagonal_matrix([1]*12 + [2^1000]) MM = M * Q MM = MM.LLL() MM = MM / Q MM = M.LLL() s0 = MM[0][0] ifabs(s0) < 128: m += "0" else: m += "1" flag = bytes.fromhex(hex(int(m,2))[2:]) print(flag) # NSSCTF{D3c1s1on_MRG_I5n'7_diFFiCulT_R1GHT?}