Prime Enigma

Looking at script.py we can recognize ElGamal crypto:

B = pow(g, d, p)
k = pow(A, d, p)
c = k * m % p

I quickly looked for the usual vulns:

But nothing. However, we can see that c1 (first line of ciphertext) and p are very close :

sage: p-c1
1

We may try to compute discrete logarithm of c1 :

sage: R=IntegerModRing(p)
sage: d=discrete_log(R(B),R(g))
[after some time]
522194440706576253339801359923264772915634530496067504511294378222169086011161345355222023334904891965055792868945181345930063539635247727258609336508464213729573000933442889881491114660596184151673117602184025505154577837077848730173588473197038267578642497447642410816850460905858369486225917489727948505153166734295375679182569391125186134558984492597161222267843707761003575819319070728089210310638911337497513995139336729314772195868459883149502755752723088834077223117441332980840398288451599558044673817473593889453264004002378346285833461482061283087291388353666226185500636081888420614659162451562870356787070502562280982956944449876730867673985005846628158375830339475415013755127902423052791732527723307545222154791525387904254648520019840028717671126963283120449097931815794444468182064960029654227834727017005195739119392094944297336168121381897569088176611422762322020047129481216806677018052321940962619244612005097096544455833082792114712334082720844463895230304132432102118858501027372168994470987330607349844853260771503131302267945499062876137971304386087188053657108874616524108952472204918119117886153374937198380231688240107566730666739197841373304121292566976941941113393059015092014068377985022692767379226623

\o/ We get the private part (d). From here it is quiet easy to find the flag:

sage: c1=1044388881413152506679602719846529545831269060992135009022588756444338172022322690710444046669809783930111585737890362691860127
....: 0792704954545172186730169284274591460018668857797629822293211923683033462352043680510103091556741556974603471769463940765351572849
....: 9489528482163370092181171673897245183497945589701030633346859075135836513878225037226911796898519432244453568741552200715163863814
....: 1456178420621277822674995027990278673458629544391736919766299005511505446177668154446234882665961680796576903199116089347634947187
....: 7789065280080047566925716669229641225661745827767073324523710012721637768412293183249031257407135741410051245619659138888997534617
....: 3534797001169325631675166067895083002751025580484610558346505544661509044430958305077580850929704003968005743534225392656624089819
....: 5863631588888936364129920059308455669454034010391478238784189888594672336242763795138176353222845524644040094258962433613354036104
....: 6438819252384892240101941930889116661655842294246681654416889277904606082648642042377170020547443379889419746612146996897065215430
....: 0626260453589099812575227594260877217437610731421774923304821790494440983623823577230674987439676046337648021513346133347839568274
....: 6608242585133953883882226786118030184028136755970045385534758453246
sage: c2=6265380231791833835303267758788740612435375756376782307759908395174807038385476612230433512399183948655327395939948491544305913
....: 0519832228832841743689290244350591737900644359806169709220102153660398728516329983804507564951202892195654820567620871222647030811
....: 3290505059049053554206416767772651512039632936795232724801922443388952796545084060280910673215063573749033668717290815841834685051
....: 5472550934010422488800823702811956639057317648411362144587690959075691631842767861059795093632398396133857852323075502261206922686
....: 7071715853936347697430259337751493747095364991386321908138072919786649906805475372673255698836823219851016018373157174188976163255
....: 7457157261911256679728707526809880224074940827825962124087677609578885077944156589121586951372962667391498824853627326311588259929
....: 7560935695128746966255078731680957971308666970400060791915655929148117366945348636645446462019008557327109946137680164958963410142
....: 2962212984780013805804113844969183565291651755912540791407996417741973307922128085091749678452799274104863860342806845294845506967
....: 1414667008770873913118369984179054902139270844669700487715140145038503768704763641223894377872853332484296603268546135216483844722
....: 413025955229649646292980986542646384960063297213437076185709400450
sage: d=52219444070657625333980135992326477291563453049606750451129437822216908601116134535522202333490489196505579286894518134593006353
....: 9635247727258609336508464213729573000933442889881491114660596184151673117602184025505154577837077848730173588473197038267578642497
....: 4476424108168504609058583694862259174897279485051531667342953756791825693911251861345589844925971612222678437077610035758193190707
....: 2808921031063891133749751399513933672931477219586845988314950275575272308883407722311744133298084039828845159955804467381747359388
....: 9453264004002378346285833461482061283087291388353666226185500636081888420614659162451562870356787070502562280982956944449876730867
....: 6739850058466281583758303394754150137551279024230527917325277233075452221547915253879042546485200198400287176711269632831204490979
....: 3181579444446818206496002965422783472701700519573911939209494429733616812138189756908817661142276232202004712948121680667701805232
....: 1940962619244612005097096544455833082792114712334082720844463895230304132432102118858501027372168994470987330607349844853260771503
....: 1313022679454990628761379713043860871880536571088746165241089524722049181191178861533749371983802316882401075667306667391978413733
....: 04121292566976941941113393059015092014068377985022692767379226623
sage: p=10443888814131525066796027198465295458312690609921350090225887564443381720223226907104440466698097839301115857378903626918601270
....: 7927049545451721867301692842745914600186688577976298222932119236830334623520436805101030915567415569746034717694639407653515728499
....: 4895284821633700921811716738972451834979455897010306333468590751358365138782250372269117968985194322444535687415522007151638638141
....: 4561784206212778226749950279902786734586295443917369197662990055115054461776681544462348826659616807965769031991160893476349471877
....: 7890652800800475669257166692296412256617458277670733245237100127216377684122931832490312574071357414100512456196591388889975346173
....: 5347970011693256316751660678950830027510255804846105583465055446615090444309583050775808509297040039680057435342253926566240898195
....: 8636315888889363641299200593084556694540340103914782387841898885946723362427637951381763532228455246440400942589624336133540361046
....: 4388192523848922401019419308891166616558422942466816544168892779046060826486420423771700205474433798894197466121469968970652154300
....: 6262604535890998125752275942608772174376107314217749233048217904944409836238235772306749874396760463376480215133461333478395682746
....: 608242585133953883882226786118030184028136755970045385534758453247
sage: c1_inv = pow(c1,-d,p)
....:
sage: flag=c2*c1_inv
sage: hex(ZZ(flag)).decode('hex')
"flag{If you whistle while you're pissing, you have two minds, where one is quite sufficient. If you have two minds, you are at war with yourself. If you are at war with yourself, it is easy for an external force to defeat you. This is why Mong-tse wrote. 'A man must destroy himself before others can destroy him.' | Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamaco laboris nisi ...}"