I am trying to work out an RSA challenge where I am given n, e, c and the result of
n mod (q-1)
However, I can't wrap my head around the maths. Could anyone help?
I am trying to work out an RSA challenge where I am given n, e, c and the result of
n mod (q-1)
However, I can't wrap my head around the maths. Could anyone help?
We can use the same trick as in this previous answer: since we have the value $n \bmod (p-1)$, $n - n \bmod (p-1)$ is going to be $0$ modulo $p-1$, that is, a multiple of $p-1$, and having a multiple of $p-1$ leads to a factorization of $n$ by computing $$ p = \gcd\left(n, \left(2^{n - n \bmod (p-1)} \bmod n\right) - 1\right)\,. $$
n mod (q-1) is equivalent to p*q mod (q-1) = p * (q-1 +1) mod (q-1) = p * (q-1) + p mod (q-1) = p mod (q-1)
${n (mod (q-1)) \equiv p \cdot q (mod(q-1)) \equiv p (mod(q-1)) \cdot q (mod(q-1)) \equiv p (mod(q-1))}$
Though there are a few good answers already I think something longer is in order.
From Fermat's little theorem we know $a^{p-1} mod p = 1$ and due to exponentiation rules $a^{(p-1)*k} mod p = (a^{(p-1)})^k mod p = 1^k mod p = 1 mod p$
If we have $n$ and $n\space mod (q-1)$ we can calculate n - n mod (q-1) which will obviously be congruent to 0 mod q-1. So we know n - n mod (q-1) = k * (q-1)
Hence $2^{n-n \space mod(q-1)} \equiv 1 \space mod \space q $
We can actually calculate this only mod n, but that is Ok, because n=pq anything we do mod n will preserve result mod q.
So we calculate $2^{n-n \space mod(q-1)} \space mod \space n \equiv 1 (mod \space q)$
subtract 1 to get 0 mod q which means. $2^{n-n \space mod(q-1)} \space -1 mod \space n = c*q$
And we have n=pq, so we can calculate $gcd(pq,cq)=q$
And together: $gcd(n,(2^{n-n \space mod(q-1)}\space mod \space n) -1) = q$
Thus factorizing n, and then we can find the secret key $d=e^{-1}\space mod (p-1)(q-1)$