0

I am working on a cryptography assignment with BigIntegers in Java. And I have these two numbers:

s1= r mod(N)  
s2= r * x mod(N)

I know the values of s1, s2, and N but I don't know the value of r and I need to retrieve x. Normal division of s1/s2 doesn't work here. I have a hint that I need to use modInverse but I don't know where to use it here exactly.

Goran Jovic
  • 9,418
  • 3
  • 43
  • 75

1 Answers1

2

Provided the inverse exists (i.e. r and N are relatively prime) this will work:

s2.multiply(s1.modInverse(N)).mod(N)

This is calculating s2 * s1-1 in modular arithmetic. The result is x mod N. Which is the same as x if x < N.

Henry
  • 42,982
  • 7
  • 68
  • 84