1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
from Crypto.Util.number import * from sympy import * from gmpy2 import invert, iroot from public import *
pq1 = 79679231796035037354449627487236220201878797729093909877127396750043503300636464774059752126148617367251988043645511172901030621825575172979048675217345099706517900079260617448298874437193769061144201311929792287772928471712053565834702260975126852624433945451405258351557569670978748727663718174543709899747
p1q = n1 // pq1 z = abs(pq1 - p1q)
def brute_force_pq(): for x in range(2, 1000, 2): for y in range(2, 1000, 2): delta = (x * y + z) ** 2 + 4 * x * y * p1q if delta > 0 and iroot(delta, 2)[1]: p = ((-z - x * y) + iroot(delta, 2)[0]) // (2 * x) if isPrime(p): q1 = p1q // p p1, q = nextprime(p), prevprime(q1) phi = (p1 - 1) * (q1 - 1) * (p - 1) * (q - 1) return phi
a = symbols('a') b = symbols('b') ans = solve([a * b - p2q2, a + b - p2_q2], [a, b])[0] p2, q2 = ans if n2 != p2 ** 2 * q2 ** 3: p2, q2 = q2, p2 assert n2 == p2 ** 2 * q2 ** 3 phi1 = brute_force_pq() phi2 = int((p2 - 1) * p2 * (q2 - 1) * q2 ** 2) print(long_to_bytes(pow(c1, invert(e, phi1), n1)).decode(), end='') print(long_to_bytes(pow(c2, invert(e, phi2), n2)).decode())
|