Search code examples
language-agnosticrsanumber-theorymodular-arithmetic

How to find m in c = m^e (mod n) if c, e, n are known


Suppose I have known java BigIntegers c, e, and n, is there a way to quickly calculate the BigInteger m, where:

c = m^e (mod n)

Solution

  • Well, sort of... Suppose that you have determined the number "d" such that

    d*e=1  (mod phi(n))
    

    Where phi(n) is the size of the set of relatively prime numbers relative to n. For example, if n=pq where p and q are prime, then phi(n)=(p-1)*(q-1).

    Then

    m=c^d (mod n)
    

    In the case where you don't already know "d", then I think it is going to be pretty difficult for you to invert that function in general. Good luck.