0

All variables are integers with a value somewhere between 0-99, inclusive.

ax + b % 100 = n and you are given everything except x.

Example: 65x + 6 is congruent with 81 mod 100.

I am trying to find a way to determine the potentially valid values of x without resorting to brute force. Is there a known method more efficient than brute force for a problem like this? If so, can anyone explain how the congruencies are found and/or possibly point me in the direction of any tutorials, books, or videos?

  • $65x+6\equiv81\bmod100\implies65x\equiv75\bmod100\implies13x\equiv15\bmod20\implies7x\equiv5\bmod20\implies$ $x\equiv3\times7x\equiv3\times5=15\bmod20$ – J. W. Tanner Dec 25 '20 at 01:04

3 Answers3

-1

$65x+6\equiv81\bmod100\iff65x\equiv75\bmod100\iff$

$13x\equiv15\bmod20\iff7x\equiv5\bmod20\iff x\equiv3\times7x\equiv3\times5=15\bmod20$

J. W. Tanner
  • 60,406
-1

The answer to your question has a very easy part and a hard part. First, the very easy part. You pose $$ a x + b \cong n \pmod{100} $$ with the example $$ 65 x + 6 \cong 81 \pmod{100} \text{.} $$ The basic strategy is the same one you would use if not reduction modulo $100$ were intended: use algebra to solve for $x$. The first step is very easy, subtract the constant from both sides. \begin{align*} a x &\cong n - b\pmod{100} \\ 65 x &\cong 81 - 6 \\ &\cong 75 \pmod{100} \text{.} \end{align*} (I suspect that you will like to remember, if the result of this subtraction is negative, to add the modulus to the difference to get a result in the interval $[0,100)$ again.)

Now our strategy calls for division by $65$, but there is a "simpler" problem hiding in your example : $65$, $75$, and $100$ have a common factor, $5$, and we can reduce by this common factor. $$ 13 x \cong 15 \pmod{20} \text{.} $$ More generally, if $a$ and the modulus, $100$ have a common factor then either $n-b$ also shares that factor and there is a solution or $n-b$ does not share that factor and there is no solution. So we check that any common factor of $a$ and $100$, $d$, is also a factor of $n-b$. Having factored $d$ out, we have $$ (a/d)x \cong (n-b)/d \pmod{100/d} \text{.} $$ The easiest way to compute $d$ is using the Euclidean algorithm to compute the greatest common divisor (gcd) of $a$ and $100$. Having found and divided out the greatest common divisor, we know that $a/d$ and $100/d$ are relatively prime. This ensures that there is a number, $c$, such that $$ c \cdot (a/d) \cong 1 \pmod{100/d} \text{,} $$ That is, $c$ acts like the reciprocal of the coefficient of $x$, so multplying by $c$ is like dividing by that coefficient.

How do we find this $c$? Use the extended Euclidean algorithm. The input is two integers, $a/d$ and $100/d$, whose gcd you want to know. The output is that gcd and also a pair of numbers, $e$ and $f$, with the following immediately useful property: $$ e \cdot (a/d) + f \cdot (100/d) = \gcd(a/d,100/d) = 1 \text{.} $$ That is $e$ and $f$ are coefficients for each input that act like their reciprocals when using the other input as modulus. For us, we want $e$ and we multiply both sides of the equation by $e$: \begin{align*} \underbrace{e \cdot (a/d)}_{\cong 1 \pmod{100/d}} x &\cong e \cdot (n-b)/d \pmod{100/d} \\ x &\cong e \cdot (n-b)/d \pmod{100/d} \text{.} \end{align*} What does the computation of $e$look like in the example? We want to study the gcd of $13$ and $20$. \begin{align*} 20 &= 1 \cdot 13 + 7 & 7 &= 1 \cdot 20 - 1 \cdot 13 \\ 13 &= 1 \cdot 7 + 6 & 6 &= -1 \cdot 20 + 2 \cdot 13 \\ 7 &= 1 \cdot 6 + 1 & 1 &= (7-6) = 2 \cdot 20 -3 \cdot 13 \text{.} \end{align*} (In the last line, we have reminded that the multiples of $20$ and $13$ we need are present on prior lines.)

This says that $2$ is the reciprocal of $20$ modulo $13$ and also that $-3$ is the reciprocal of $13$ modulo $20$. We want the latter and we add the modulus, $20$, to it to get a small positive number.
$$ 17 \cdot 13 \cong 1 \pmod{20} $$ So, \begin{align*} 17 \cdot 13 x &\cong 17 \cdot 15 \pmod{20} \\ x &\cong 17 \cdot 15 \pmod{20} \\ x &\cong 15 \pmod{20} \text{.} \end{align*}

If it had been the case that $d = 1$, so we were not working with a reduced modulus, we would be done. However, when $d > 1$ there are multiple solutions. We know that $15$ is one solution and we know that $15$ plus multiples of $20$ are solutions. Since the original congruence is modulo $100$, we want to know all the "$15$ plus multiples of $20$" in $[0,100)$. (By division, there are $100/20 = 5$, and in general, there are $d$ of them, but let's write them down.) They are $15$, $35$, $55$, $75$, and $95$. (If we add $20$ again, we "wrap around" back to $15$.)

Let's test these: \begin{align*} 65(15) + 6 &\cong 975 + 6 \\ &\cong 981 \\ &\cong 81 \pmod{100} \text{,} \\ 65(35) + 6 &\cong 2275 + 6 \\ &\cong 2281 \\ &\cong 81 \pmod{100} \text{,} \\ 65(55) + 6 &\cong 3575 + 6 \\ &\cong 3581 \\ &\cong 81 \pmod{100} \text{,} \\ 65(75) + 6 &\cong 4875 + 6 \\ &\cong 4881 \\ &\cong 81 \pmod{100} \text{, and} \\ 65(95) + 6 &\cong 6175 + 6 \\ &\cong 6181 \\ &\cong 81 \pmod{100} \text{.} \end{align*} This shows that all the numbers we found are solutions. The argument laid out above shows that these are all of them.

Eric Towers
  • 67,037
-1

$ax + b \equiv c\pmod{f} \iff ax \equiv (c-b) \pmod{f}.$

Therefore, the general problem reduces to attacking

$$a(x) \equiv e \pmod{f}, ~\text{where}~ a,e,f ~\text{are known integers}.$$

Suppose that $d =$ gcd$(a,f).$ If $d$ does not divide $e$, then the problem has no solution. If $d$ does divide $e$, then the problem is equivalent to

$$\frac{a}{d}(x) \equiv \frac{e}{d} \pmod{\frac{f}{d}}.$$

Therefore, WLOG, $a,f$ are relatively prime and the general problem to solve is

$$a(x) \equiv e \pmod{f}.$$

One approach to attack this general problem is compute $s$ such that $a(s) \equiv 1\pmod{f}.$ Since $a,f$ are relatively prime, $s$ must exist.

Once $s$ is computed, then you have

$$x \equiv [a(s)](x) \equiv e(s) \pmod{f}.$$

Therefore, the solution will be $x \equiv e(s) \pmod{f}.$

One standard way to compute $s$ is via the Euclidean algorithm.

The easiest way to demonstrate this is by example.

Let $a = 53, f = 75$.

Then $75 = 53(1) + 22.$
$53 = 22(2) + 9.$
$22 = 9(2) + 4.$
$9 = 4(2) + 1.$

Therefore:
$1 = 9 - 4(2)$
$= 9 - (2)[22 - 9(2)] = 9(5) - 22(2)$
$= 22(-2) + (5)[53 - 22(2)] = 53(5) - 22(12)$
$= 53(5) - (12)[75 - 53] = 53(17) - 75(12).$

Therefore, $(53 \times 17) \equiv 1\pmod{75}.$

user2661923
  • 35,619
  • 3
  • 17
  • 39