The primes used for the modulus N
is of the form 2 ^ x - 1
. Such primes are called Mersenne's primes, named after French mathematician Marin Mersenne.
A quick hack for factorisation is to lookup FactorDB, as I assume the primes are studied extensively. The result from FactorDB shows two primes
Another solution involves a bit of math. Suppose the two primes used are
Thus, we have:
We thus can divide p,q
should be trivial after this.
Python Implementation:
xxxxxxxxxx
from Crypto.Util.number import long_to_bytes, inverse
n = ...
e = 65537
c = ...
z = n-1
a = 0
while z % 2 == 0:
z //= 2
a += 1
p = (2**a - 1)
q = n // p
phi = (p-1)*(q-1)
d = inverse(e, phi)
m = pow(c, d, n)
print(long_to_bytes(m))