51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from Crypto.Util.number import getPrime, bytes_to_long, long_to_bytes
|
|
from sympy import gcdex
|
|
from math import gcd
|
|
|
|
|
|
flag = "h4tum{...}"
|
|
m = bytes_to_long(flag.encode())
|
|
|
|
e1, e2 = 65537, 17
|
|
assert gcd(e1, e2) == 1
|
|
|
|
while True:
|
|
p = getPrime(512)
|
|
q = getPrime(512)
|
|
n = p * q
|
|
phi = (p - 1) * (q - 1)
|
|
|
|
if gcd(e1, phi) != 1 or gcd(e2, phi) != 1:
|
|
continue
|
|
if m >= n:
|
|
continue
|
|
if gcd(m, n) != 1:
|
|
continue
|
|
break
|
|
|
|
c1 = pow(m, e1, n)
|
|
c2 = pow(m, e2, n)
|
|
|
|
|
|
print(f"n = {n}")
|
|
print(f"e1 = {e1}")
|
|
print(f"e2 = {e2}")
|
|
print(f"c1 = {c1}")
|
|
print(f"c2 = {c2}")
|
|
|
|
x, y, g = gcdex(e1, e2)
|
|
|
|
x = int(x)
|
|
y = int(y)
|
|
|
|
print(f"x {x} | y {y}")
|
|
|
|
if g == 1:
|
|
print(long_to_bytes(pow((pow(c1, x, n) * pow(c2, y, n)), 1, n)))
|
|
|
|
# n = 65707100137186888475953513086898008905139437630875837854644107822814283110769943579567177881705884274398390781130006134316686487768614537736768547066999613093550734163327713557603091143994827233687646229561643622445920391793762897858845575115299394349389922615093939357420040773283610664101678989419396092347
|
|
# e1 = 65537
|
|
# e2 = 17
|
|
# c1 = 7884926352513340573382039144424214727926794782607805142710494009270484466220925417591780881028724970568583944980873161206083606075384860708927042438650854760874336954047477893939539790216193654418650762594184302293754065850164791109812773425623526938062911997730089936569977360813014753477745012650386772981
|
|
# c2 = 11375974342330610521528067622440162683299269265928514681623828493060125481649837931599740517662407981391104665035998955029942650948493441810229768425798821925645814933013176879334289941104021860757801270190361115580835274215465891021181470368445998384179348332817603554056032081626905073456569537572535147729
|