How to permute remainders of CRT between residue classes?

23 Views Asked by At

I want to know how can be permuted the remainders of the CRT.

How to go from

$a \equiv r1 \;(\bmod\; n_1)$

$a \equiv r2 \;(\bmod\; n_2)$

to

$b \equiv r1 \;(\bmod\; n_2)$

$b \equiv r2 \;(\bmod\; n_1)$

How to find $b$ if I know only the value of $a$, $n_1$ and $n_2$ ?

1

There are 1 best solutions below

0
On BEST ANSWER

A general method for finding $a$ such that $\begin{cases}a\equiv r_1\pmod {n_1}\\a\equiv r_2\pmod{n_2}\end{cases}$ is as follows:
First find $m_1$ and $m_2$ such that $\begin{cases}m_1\equiv 0\pmod {n_1}\\m_1\equiv 1\pmod{n_2}\end{cases}$ and $\begin{cases}m_2\equiv 1\pmod {n_1}\\m_2\equiv 0\pmod{n_2}\end{cases}.$ Then the desired $a$ can be seen to be $a\equiv r_1m_2+r_2m_1\pmod{n_1n_2}.$
To permute $r_1$ and $r_2$, just change $r_1$ and $r_2.$


A faster (?) way.
Notice in the above expression that $a-b\equiv r_1(m_2-m_1)+r_2(m_1-m_2)\equiv(r_1-r_2)(m_2-m_1)\pmod{n_1n_2},$ so it suffices to find $m_2-m_1.$ But $\begin{cases}m_2-m_1\equiv 1\pmod {n_1}\\m_2-m_1\equiv -1\pmod{n_2}\end{cases}.$ Consequently we can take $b\equiv a-(r_1-r_2)(n_1(-2n_1')+1)\pmod{n_1n_2},$ where $n_1'$ is such that $n_1'n_1\equiv1\pmod{n_2}.$


P.S. I assumed that $\gcd(n_1,n_2)=1.$
Hope this helps.