-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsolve2.sage
31 lines (27 loc) · 7 KB
/
solve2.sage
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
cts = [(28721290457348876007351707474261336222897740140783775046256595793280015466308033591047121821691726535755061599829772573737710856047835076995131992726368430191083670549344365180695374983467638317240949933818909686666689385598309561201288517583460489082860970717692447891872033418790013774694281570994869789674588045688726842544753838737014754750910507447774741855101719319104856821494174408447048716283641298940246530643617043110270134238970175545582846915126076329993463647222893590248818908055391576197310976205322915098547097329497062758920630623334942950810234236681021530724349451378628179452060630631058577551511, 11, 6818274736105840123930138407625642345618766372876047480022552370924378701350258959889241605056033788167598169968889762896202123348179960419280761475957886865786365071000399677873865053583265550122628886458430290722447418861861544430758668692216441237773267123840502592441364389829672920813034778682822592690987099280918217126204323482149849661695843504446036805986746049193892026194660251940329380384586023824218068714572156437646925271719584517685459409479235259828795683538056974485891691454312233852306953045492557845104485877573681713493356795771430741228799756188603915292381631719186205017093378577834580790839, b'\xb88\xb8\xdc\xe8\xe9\x9at,\x14s\xb4H\xd3Rl'), (30039264509286110830884434965465992402084321977601656714377137863721020593648852075108766693078149375357882142749250127727595312772443303886626670222983540428731387299125464573561708802091372992704347956454583620694094915893253194360110279254782988886880687205510622479922941615762785416665413306800921859536791556366982974842980270187906182533377353418259899512864997923451930986821692579252315648453006999272272372657393155950393665243737992063893672588096356291736385186193453654351483549680915878107112524766295864200501586383040173630062317333320445367066247358068602536679923881230143082058207101324220668285813, 11, 2713315242255387826270430477598160248381576302619556468683658680964071354208471487907071150983225660157018240963906727398924907889576485814816164845395883739797456098568129449604503475321248753264122090285391545571257809945234490242027290654944165401608112816608639731895941372770053348623122961118730265264152301564717831368591896065007424625525397759239040463695706159965543440281259569676444847779594034325179541127257091538910410521429680318855863266624057087654553110938864957376997480301452630529686504820872782579784735772171643535227224753373496147327720894240600747414701490603908663798335796182970567850528, b'\xc6<\x90\xb9\x8f\xd8C\x12C\x00q\n \xd8E\x87'), (18597914387906864332932485350433890260795848434008594952626599161189956003498450947126601756594294156593736247596148560104870520756978277539038438854548502928142129801250426626877728640957412425160349005446017611462316836644538576586005672726314166393041130789762697625790822203748934291166867856719997267645966406596567001270031275098894784034803599057934055304361228305116819893758703931984583148197509865135463195859057085921447967393028850147803557553899156647710885388847089340728559078235688424536818035371439079959572161774726298761126460682901201457172367570324465412574011005827820451834776187422164007136279, 11, 8503635477796385507374207650722211191948434112836586272430860324006959182941387750793079667960378920880509819985457209738622111477203824653879482409401237136920565176142973457613394038935924345898317133244360209598711200284535904119961489653879822332040595427144288539928622560615595309843342086706532117915170704904295186744652483158069323313672210341056214119093120431806725718457862700317668708059623670639792898970785416740241193338695846372964600979229308391875259783343832678903558543286615009723683382405760469706445806183716422144864454734338170899459023148133043134404931616117026496642593037961512125560776, b'\xd36a\x0e$E\xc2\x88\x05\x87\r*u\xbfT\x93'), (16954161277748485375764044920232295323455338209318429045468024075479437545978857796649873333955738018486235576226089180692545049483664009975072164226425384829793991418738086011346145434448950775393644744295864375069456474111770894929938455011804219884608159875830299545955714549007309527087763929328625623247798093945214976837003611082073400035119525736175701061150221878999641231143719084475405828635865431220325212147839648009933154992440319968412595160972853465481486369205811910885042860518461993616629404979410363471174626819359563104189365185314971820113839865500838653154986497384929739322339516152849706471497, 11, 15150005624253916609290397004045592059175143301605724558737673527852430613195311620674918292151036566971042565456390559457226009818722426745350566233821028495375739228818851111639442619917411377590441952371283569934989373662451736809616772844420645232618364359052095363844885734213069725780941730633542639301181246805819107308734490711365829451382403188705433655678348800443052322871909078991139442830733623773121693640004000864782435771081881967051452131686341370301232712567849320597965028709465930956677358094625772196869094219769249882759638799656421347827004038993500877880832229070391891960153564671638245786295, b'e\xac\xcb\xaao\xf7\xc8\x14\xfbH\xae\x9b\x92\x12\xe5r'), (13559897055550603442964360781347601892801699286534237855330955852762128939188119796525569967251371651915415847981896165797560623718959563363716964203490843898835473481846852197864407407228963951767292888427430871429427812878469837985312886207760107753627141458221998578563161389289179235069010562114167869772681537485534345891493052987909940960790060103202803330012362192707234368358448138193821559016070452408628790425479333031501113015174895680170612621417448653772085299024783223876240726043771333696444742264015414847010412878228070604064998737539295002011676099041291340466859385749459909717010211442799144444551, 11, 8724417032489388024914756600041564045891547097139462413963624709172360887851867921510947556407324246169481938888969312584760392771505149072628848519727828747041433224932478553113130256067220881569127629275599400038384228618700586675363938112056986715044912122207349541711633598653789905892626183334400258764609982242780764821060277823820555225479338363088270682995478620059720381055101375879547032888788273923669380082266558885307977512088937538795906778904250561253360019056618626783802630100726996153489163302540177050573170553428859735976065328313809449391326015084652674406095366383004588375138244207996713520090, b'\x0c}\xa5\x871\xf4O\x06\xb4\xfa\x96> \xa0\xb5\x87')]
def two_dim_crt(c1, c2, n1, n2):
k1 = pow(n1, -1, n2)
k2 = pow(n2, -1, n1)
return c1*k2*n2 + c2*k1*n1
def multi_dim_crt(cs, ns):
i = 1
c1 = cs[i-1]
n1 = ns[i-1]
while i < len(ns):
c2 = cs[i]
n2 = ns[i]
c1 = two_dim_crt(c1, c2, n1, n2)
n1 *= n2
i += 1
return c1
from functools import reduce
ns = [ct[0] for ct in cts]
N = reduce(lambda a, b: a*b, ns)
P.<x> = PolynomialRing(Zmod(N))
polys = []
for n, e, c, r in cts:
r = int.from_bytes(r, "big")
poly = (2^(16*8) * x + r)^e - c
polys.append(poly)
combined = multi_dim_crt(polys, ns).monic()
print(combined.small_roots(X=2^432, beta=1, epsilon=1/16))