import gmpy2
from gmpy2 import mpz

# Given values
n = mpz("72924071154427172508233508122281984558173797746827918913680016580102742871048315866240181038360994449257562662327564504931510166665707037626188109286571564583920642302321319466970237538368044065823881407136450895882009903207003408989566248146397117090978042491114555846680338575893805018583672003051790871493864754064581401822436578429194689889857507809725468520137406724246338072181005939476470424338019513451358969303019164071159829433541457985121933186581076034249852954215735741570647298094288448433989396019662099143860678922964832131697049968334609835736912296323615045650181081774501337400303329098267539794130098116874976030246694509073990643230710266693921")
e = 65537
c = mpz("46442091764452821275410522862135030078688821053426124090015667047295776510904030929085828969434259901897114637848129679976826201612750645858467676162938723824399363909712437626520442520873126212071906004825480014346304377049815007457777904758490602536930662198260243072575663478292970254099181161466881632306341428890781517217158988967945095119298965541664770955415202985975318253306654255800049094206201315306457976098146784891586817925873563992855063765905634248115296743046220064468888309937739729958814066317008974630622539107335820551984301544590537917852647145181229387667509308710613146905721339957026816236754915771881343483791931319424841581518152125846578")

# Step 1: Find p (since n = p^2)
p = gmpy2.isqrt(n)  # Square root of n gives us p

# Step 2: Decrypt the message using modular exponentiation
# We need to find the modular inverse of e mod (p-1)
phi = p - 1
d = gmpy2.invert(e, phi)

# Step 3: Compute the plaintext m by applying the modular exponentiation
m = pow(c, d, n)

# Convert m back to a readable format (plaintext)
# Since the original file was a text file, we convert m back to bytes
m_bytes = m.to_bytes((m.bit_length() + 7) // 8, 'big')

# Display the result (assuming it's UTF-8 text)
print("Decrypted message:", m_bytes.hex())
