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
|
from Crypto.Util.number import * import re
e = 113 c = 1028324919038104683475485759234995158466543298184637219012354053883391759172761125802189697762778242175407876548832454351014064525118465877297277847501477586955680645311999174005606833294172830817159 ps = [953730950786751671162019537171974567, 232079231415308325450092906880606082069, 88067722275537586769787599991567203589751, 24335212484189159197840692460327461505035059, 7832299017937880395583715032476962329929226581, 1656848589754467667368312855929759764100120657831, 385788223643735590500185001710758495904528462058461, 135813272566456906193934636644217527100917542578856697, 37185691759470013533730603170661686570987787098353146897, 6623023178993627032758350846838617937710601663528839184727, 954412804126450754097808991490470782833291028309980575506163, 350121371461894793578110243222665782247737840410076591434903787, 66882708962198932251728043152245270662769508317424500666902658099, 43449898447639409732732812916430042263570178747794530133229640125923, 11136261905010083405430254612464029672882837025885682392810368001188527, 2623629589005115152329094552749299711026240699896424120660145647226563547, 262775599542220820608778738911414710660835549772895468394761119434220071003, 102366458668689911004027849640392002821642295855327735994412634235696717329671, 15874438801602936764330936047390981280096007684699625987478211613419079727910193, 4479430800690915874719403516331677127806963529247809966024777708496270901092401687, 1328165608715012145707239303399129070657427496129541416861187541092152796676371237057, 368461902207817023013078031477042541053987571003677386333567043030477451518424731838173, 206721456778089912780641186795393376537372828449722520397829606593267585681448641482345737, 43870497594014737833600078975099212558645315030912084285417550950854483979406797450479252891, 14702310219802004876082313481498680940324963613770096574742182597840558294030859405666549879531, 5952590790902091635268726673538951527433355660839816621733964706901441977862333411532558667717227, 978009050697262759337388871320370165458800566798280419667959552859180906066907114053826258140106617]
def get_roots(ii, ci): pi, qi = ps[ii], qs[ii] R.<x> = Zmod(pi)[] f = x ^ e - ci f = f.monic() res1 = f.roots()
R.<x> = Zmod(qi)[] f = x ^ e - ci f = f.monic() res2 = f.roots()
sol = [] for x in res1: for y in res2: mi = crt([int(x[0]), int(y[0])], [pi, qi]) if ii != 0 and mi < ns[ii - 1]: sol.append(mi) print(f'No.{ii} x = {x}, y = {y}') elif long_to_bytes(mi).startswith(b'DASCTF'): print(long_to_bytes(mi)) return if not sol: return for jj in sol: get_roots(ii - 1, jj)
ns = [] qs = [] with open('output.txt', 'r') as fp: regex = r'[n] = (\d+)' output = fp.readlines() for i in range(len(output)): if re.findall(regex, output[i]): ns.append(int(re.findall(regex, output[i])[0])) qs.append(ns[i] // ps[i]) assert False not in [ps[i] * qs[i] == ns[i] for i in range(len(ns))]
get_roots(len(ns) - 1, c)
|