Danny Siu's Personal Blog

When the modulus m is a product of distinct primes, the decryption will always work

April 25, 2020 | 2 min read

As long as mm is a product of distinct primes, the decryption will always work even the message aa and the modulus mm are not relatively prime. i.e.

aeda (mod m) aZ wherea^{ed}\equiv a\space ({\text{mod}} \space m) \space\forall a \isin \Z \space\text{where}1. m=p1p2pr, pi are all distinct primes2. gcd(e,ϕ(m))=1,edϕ(m)v=1 where e,d,vZ+\begin{aligned} 1. \space &m = p_1p_2 \dots p_r, \space p_i \space \text{are all distinct primes} \\ 2. \space &gcd(e, \phi(m)) = 1, ed - \phi(m)v = 1 \space\text{where}\space e, d, v \isin \Z^+ \end{aligned}

Proof:

m=p1p2pr\because m = p_1p_2 \dots p_r

ϕ(m)=(p11)(p21)(pr1)\therefore \phi(m) = (p_1-1)(p_2-1) \cdots (p_r-1) (Euler’s phi function formula)

ed=1+v(p11)(p21)(pr1)\therefore ed = 1 + v(p_1-1)(p_2-1) \cdots (p_r-1)

If gcd(a,pi)=1gcd(a, p_i) = 1, by Fermat’s little theorem, api11 (mod pi)a^{p_i-1} \equiv 1 \space(\text{mod}\space p_i). Then,

aedaa1+v(p11)(p21)(pr1)a (mod pi)a(av(p11)(p21)(pr1))a (mod pi)aa (mod pi)0 (mod pi)\begin{aligned} a^{ed} - a &\equiv a^{1+v(p_1-1)(p_2-1) \dots (p_r-1)} - a\space(\text{mod}\space p_i) \\ &\equiv a(a^{v(p_1-1)(p_2-1) \dots (p_r-1)}) - a \space(\text{mod}\space p_i) \\ &\equiv a - a \space(\text{mod}\space p_i) \\ &\equiv 0 \space(\text{mod}\space p_i) \end{aligned}

If gcd(a,pi)1gcd(a, p_i) \ne 1, then gcd(a,pi)=pigcd(a, p_i) = p_i since pip_i is a prime number and gcd(a,pi)=1 or pigcd(a, p_i) = 1 \space\text{or}\space p_i and hence aa is a multiple of pip_i.

aeda000 (mod pi)\therefore a^{ed} - a \equiv 0 - 0 \equiv 0 \space(\text{mod}\space p_i)

So, whether aa and pip_i are relatively prime or not, we always have

aeda0 (mod pi)    aeda (mod pi) i=1,2,,ra^{ed} - a \equiv 0 \space(\text{mod}\space p_i) \iff a^{ed} \equiv a \space(\text{mod}\space p_i) \space\forall i=1, 2, \dots , r

Since pip_i are all distinct prime numbers, we have aeda (mod p1p2pr)a^{ed}\equiv a\space ({\text{mod}} \space p_1p_2 \dots p_r) and hence aeda (mod m) aZa^{ed}\equiv a\space ({\text{mod}} \space m) \space\forall a \isin \Z.


Written by Danny Siu who lives in Hong Kong. You should follow him on Twitter