# Untitled

unknown
plain_text
a month ago
6.0 kB
3
Indexable
Never
```#!/usr/bin/env python3

import hashlib, sympy
from Crypto.Util.number import long_to_bytes
from Crypto.Cipher import AES
from sympy.ntheory.modular import crt
from sympy import Poly, symbols, N

def F(x):
return int(
487287452132 * pow(x, 4)
- 2476267878632 * pow(x, 3)
+ 8028242452324 * pow(x, 2)
- 56195810567274 * x
+ 232842749872983
)

def inverse_F(y):
precision = 100
x = symbols("x")
solutions = Poly(
487287452132 * x**4
- 2476267878632 * x**3
+ 8028242452324 * x**2
- 56195810567274 * x
+ 232842749872983
- y
).all_roots()
solutions = [N(solution, precision) for solution in solutions]
solutions = [int(solution) for solution in solutions if solution.is_real]
solutions = [solution for solution in solutions if F(solution) - int(y) == 0]
return solutions[0]

def decryptAES(ciphertext, key):
md5_hash = hashlib.md5(
long_to_bytes(key)
).digest()  # Hash the key to ensure 16 bytes
cipher = AES.new(md5_hash, AES.MODE_ECB)
return cipher.decrypt(ciphertext)

RSA_Result = [[41501379666480956842379912479515283210047000695182233265152425016282367452513217366288092719013600751517853886959045908633879472632893989822306167109013802616228985521886090998718942359697804647403238624751919382984776193335784789572478036724375667021512979423806038612283833645234181996059587020592158244563, 56592674237648049766253602798651671329817982169411861355484547690814303082038525364853725442251338084156177381277497313621166105256108739293705644699343764908412593720049615124493803982332435498636198487144283301528748540710774185365663961065477933908605295712356723467956794340834304518911580681445440879931], [31881796767071979197927338047593024792400147535736421195582081593719833036417519321433573710096607445476846943475459965060429220142490885728351635947620942082135514459011392652245545943770721996470825650071613297329299025336277830326914626268202373962381573677506441477185609873315736351746477806499598091711, 137284863530920801661487781846775565086168002260072667913641028124073870670055742666884608237258069233181277857939643459974416391050470227359053733137129906722619425254165921913680357079914962892145457605842057309947704741991892782513822512199347125003305718322571745011650533697279371565178197178464245777321], [6727270529841002262709843376741083024857409235134460354529909814619953416757951941536916709818291060783624120591869151922766334172479218071854834569585452431374956117414709692778511325903193742584575660482989618345508810780492770699553346287816208843341353838445051755712124799476731253839449586938541188027, 76341833708986882579438125571454264270807834523599945012139945984340149970056596103926154711923128043335657864627414516089483907605410643967830431756266929326717321140262066731539693961054674637965562192214542557120758635762574157002391416418697537547319765838733979631087453401062094468281664951831097885667], [79499460358333083147534123145708235548416549037302865267522303852969104769395067027881215506363048316085389315150016646295761331183118419283005513644283295256839132678253733031241095622019927729141844693446609218462940579634183093569906466004003523666251339616536679655567474305543505953630596812502338117910, 144198497028415064307959916825358963032255282305869293372080813848382894922015182348244518869808724680457618305436577218872718816112656851028923253170287505315540793462120118708861161546101328642042723246987914688817181191897856217193918505898340422559845623716409501685140680585111186480868633705087222079617], [56919793419958559323349806334078672727864707416761568607298192613861788065895322107308504255060671305252724089116126357587416340076572159671831009673467748819406520042999893426279337794450041020645642375325638381288853333679519673369566651427250908994318888061351438568696590458591175209033341499460889065793, 122569057381665146455712325705465113084799639177404105120687380778800645391389608011447891365477804626487169260637186915120167960951170953456454101522973283592758676849089890947752479327496304338602371184209881067157807587535033494157085055479589188176369602410965927396234187501639929393229801389046249538939], [58445366609769283320591446055140492708351121550915681162287109127246951237744775477182696098302583927204842878560356011732547828141155781008943718576222470528371740488692633622369651067657965996319297238022836259962000532049267352231339091042180976770569776145569935392493294773839825244691603789323877813510, 89608589115777838709230408707083349208858986324629129959505509244643840194325354216945871028181395282538334627110918140208430708321995537892217666995159696906827689322836324797007733995936934444413104910998640679431869518059460283314796649471340722264650575032251258069808837493707903184005622040045919094997], [12962969352547483506080189259031118508223460475612457550439956432878628549240880687575016955858847742619760559362013586011406967939547741585437652280584880798794119403802309224266856504241867806149913330665808235406857314014720654809833231710673292025156412480611915645154548965225483132415534833159367006007, 157519648624142075863977450572117548346713582799076884595678781967064904073164550406297815689591911379822277406429658420948188729504535663403281799690192381323879476777402486386549088574426845614493776600689547189716271434557435563274311119145872938738851831979525974988504670082402870550953608542212870443333]]

n = [i[1] for i in RSA_Result]
c = [i[0] for i in RSA_Result]

# Step 1: Perform CRT to find e ^ 7
rsaMessagePow = int(crt(n, c)[0])  # m ^ 7
transformed_key = sympy.integer_nthroot(rsaMessagePow, 7)[0]

ciphertext = ""
with open("flag.pdf.enc", "rb") as r: