0

Given two values $a$ and $b$, is there an equation/algorithm that can efficiently find $n$ in the following equation?

$$a \equiv b \pmod{n}$$

I found this question while looking for an answer, but it's the inverse of what I need.

Edit: I'm not sure why my question has been marked as a duplicate. The linked question discusses the definition and name of the $\mod{}$ operator, while my question is about the usage/reversal of the $\mod{}$ operator.

  • This is just a first thought, but if there was an efficient algorithm to find all such $n$, then prime decomposition would also be easy: to decompose $a$, find all such $n$ for $a$ and $b$ where $b$ is the product of all primes up to $a$ (or at least all primes in the databases used by the usual RSA implementations). The prime factors of $a$ will be among those $n$. – Vercassivelaunos Mar 25 '23 at 09:02
  • @Vercassivelaunos: what's an RSA implementation? Is that an algorithm for primes? – E. Jones Mar 25 '23 at 09:03
  • Not sure what you are hoping for. Any factor of $a-b$ will work. In general, factoring is difficult. – lulu Mar 25 '23 at 09:03
  • RSA is the most common encryption algorithm which is based on the fact that if we take two primes and multiply them, it is very hard to find those primes from just their product. – Vercassivelaunos Mar 25 '23 at 09:05
  • By the linked dupe, by definition $,a\equiv b\pmod n\iff n\mid a-b,,$ i.e. the solutions $,n,$ are precisely the divisors of $,a-b,,$ which can be found by integer factorization algorithms.. – Bill Dubuque Mar 25 '23 at 09:20
  • Re: your edit: it appears that you are confusing $\rm mod$ as an operator vs. relation (congruence). This too is explained in the linked dupe. – Bill Dubuque Mar 25 '23 at 09:20

1 Answers1

-1

By definition, $a \equiv b (mod n) \iff a = nk + b$ for some integer k. So $n = (a - b) / k$. There are thus multiple solutions based upon the factors of $a - b$.

If $a - b = 6$, for instance, then k is any of $\{ 1, 2, 3, 6 \}$. For any selection of k, n = 6 / k.