Last active
September 19, 2019 23:56
-
-
Save Nicholaz99/6f7d7e435c46abe7ad7b1f82aff3b233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sage.all import * | |
from Crypto.Util.number import * | |
n1 = 16665162598091416675035243372929255215330237988600063606115453406246759269279788760269977993441302227754535063989940158801403082299136924692382379772238783511717805089453627769958409474798262234585212880036578100065244955419654350030210214612873050000707217728997449651244785327256673209001617229204596903739745000294771409411741050416912250410842101344110865361910624576900847453308353320549785990249062848385268654951594713494728031930339317011245422247813046177464952338694367015023462166849724348822067012372916419798329882575892837697474973759070677459272935998500533063881083981623170007582400032456357369057331 | |
n2 = 12327967666608400089684292637697723886692743047311943117634453297696672596602132832770180763706410481136385428797064430470744303260875130025364968184033440278168149230015012651339700361911455246276535179299003908649820055478166532502332896978314839548456221498409689020137730201961802661796522959185289676293168958100994789278927928614060667061494784764996405812503722093377901735054396731379083755482112808051044511509930814761992548239396939638987562480503407989092943629763956630828533555667490559450650474172687439499014071217245302164885369990725379389835929411041979972161099398047802667999958241746711037377019 | |
a = 651462892194717457221755220174856890047929116650078860763950453454949587828096234616831315488704251531401792609600066162972268247282594239275742779598127716518383086923760296725577120504817396207799394031948181614036825015620143890966541423830037471615505961486852765107641800802598611031433822941186606730 | |
b = 442296418993240063675266142454740191465599525570774611710139968474930425844945295951472133337584882919079119792948035796322583493017921438477858246253211352232247225094327539626813294415765610979636199753519138117254187197466480294243789769005210602152862859358315543589192060482998253522480707816974954144 | |
c = 7899134322955645246464106475661567371519411492907819361218537936109003314263398594946847506479710018156056516572597388680265129465680577498126784603599657304217232946737359907830193767343579320119617475061103397775839997585822041520474984253434505877605909867411822079954503549880731554010164405517963598831678530319685550356656748243909520671642189043288332595811057445820791781035731118992393238366930032136586970961554635691292784903624264141333213116074342104788426932419021114413087179933685563867060402709899375500659953038354210747849030819495299042436380277429490866466199179979698665821921998413237763283416 | |
e = 65537 | |
k1 = 0 # assume that a = (p1 - p2) because (p1 - p2) smaller than (q1 - q2) | |
for k2 in range(1, 10000): | |
print k1, k2 | |
p1 = var('p1') | |
p2 = var('p2') | |
q1 = var('q1') | |
q2 = var('q2') | |
sols = solve([p1*q1 == n1, p2*q2 == n2, (p1 - p2) == a, (q1 - q2) == b+ k2*(p1 - p2)], p1, p2, q1, q2) | |
if(len(sols) > 0): | |
temp = str(sols[0][0].rhs()) | |
charset="()/*+" | |
found = False | |
for ch in charset: | |
if (ch in temp): | |
found = True | |
if (not found): | |
p1 = int(sols[0][0].rhs()) #p1 | |
p2 = int(sols[0][1].rhs()) #p2 | |
q1 = int(sols[0][2].rhs()) #q1 | |
q2 = int(sols[0][3].rhs()) #q2 | |
phi = (p1 - 1)*(q1 - 1) | |
d = inverse(e, phi) | |
m = pow(c, d, n1) | |
print "[+] p1:", p1 | |
print "[+] q1:", q1 | |
print "[+] Flag:", long_to_bytes(m) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment