sahasumit288's blog

By sahasumit288, history, 8 years ago, In English

Assume we want to find a % n. Let n = p1 * p2. Find a % p1 and a % p2. Call a % p1 = x1 Call a % p2 = x2; For finding a % n. We can do following. Write a % n = x1 * alpha1 + x2 * alpha2;

How to find alpha1 and alpha2 and how to prove that a % n = x1 * alpha1 + x2 * alpha2 ?

  • Vote: I like it
  • +17
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it +32 Vote: I do not like it

Are p1 and p2 distinct primes?

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    yes

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      Well in that case you are looking for the Chinese Remainder Theorem. It was not clear to me how to use it to solve specific cases, so I will try to explain my best here.
      You are trying to find a such that
      a ≡ x1 (mod p1)
      a ≡ x2 (mod p2)
      The solution then is:
      a = x1N1[(N1) - 1]p1 + x2N2[(N2) - 1]p2
      Here is what each value means:

      The value [(N1) - 1]p1 means "the modular multiplicative inverse of N1 with respect to p1". Formally, this means that:

      N1[(N1) - 1]p1 ≡ 1 (mod p1)

      Similarly, [(N2) - 1]p2 means "the modular multiplicative inverse of N1 with respect to p2"

      N2[(N2) - 1]p2 ≡ 1 (mod p2)

      How do we find [(N1) - 1]p1 and [(N2) - 1]p2? We can use Fermat's Little Theorem to compute the modular multiplicative inverse of a number with respect to a prime.
      We have
      ap ≡ a (mod p)
      Dividing both sides by a we get
      ap - 1 ≡ 1 (mod p)
      Again
      ap - 2 ≡ a - 1 (mod p)
      Therefore, the modular multiplicative inverse of N1 with respect to p1 is equal to N1p1 - 2. (Note: this value can get very very large, the value you really want is N1p1 - 2 mod p1)
      Similarly, [(N2) - 1]p2 = N2p2 - 2 (Again, this value is usually gigantic, so you compute N2p2 - 2 mod p2)

      Now that you have all the variables, you can compute a mod n.

      Please let me know if anything is unclear/wrong. That's it!