[Math] Finding involutory keys in Affine Cipher

cryptography

Let $n=pq$ , and let $p$ and $q$ be distinct odd primes.

Deduce that the number of involutory keys in the Affine Cipher over $\mathbb{Z}_n$ is $n+p+q+1$.

I honestly have no idea how to go about this problem. I know that
$n|(a^2 -1)$ and $n|b(a+1)$ but I have no idea how to use these to show
that $n+p+q+1$ is the number of involutory keys in the affine cipher.

Best Answer

Thinking out loud: suppose $E(x) = ax + b \pmod{n}$ and that $E(E(x)) = x \pmod{n}$ for all $x$, so that

$$x = E(ax+b) = a(ax+b) + b = a^2x + (a+1)b \pmod {n}$$

Taking $x=0$ gives $(a+1)b = 0 \pmod n$ or $n | (a+1)b$. Then we are left with $x = a^2x$ for all $x$, so taking $x=1$ we indeed get $a^2 = 1 \pmod{n}$. The latter has $4$ solutions (for a proof see here e.g.), namely $a=-1$, $a=1$, the unique solution $s$ (modulo $n$) to $y=-1 \pmod{p},y=1 \pmod{q}$ and the unique solution $t$ (modulo $n$) to $y=1\pmod{p},y=-1 \pmod{q}$. (the Chinese remainder theorem guarantees their existence and uniqueness).

$a=-1$ always has $(a+1)b = 0 \pmod{n}$, for any $b$ (so $n$ of them) (this corresponds to all encryption functions of the form $E(x) = -x+b \pmod{n}$)

For $a=1$ we get $2b = 0 \pmod{n}$, this can only happen if $b=0$ as $n$ is odd. This thus gives $1$ solution: $E(x) = x$. (Not a very strong encryption :) )

For $a=s$ with $s+1 = 0\pmod{p}$ and $s-1 = 0 \pmod{q}$ we only have $pq| (a+1)b$ iff $q | b$. So we get all multiples of $q$ below $n$ ,of which there are $p$ ($b=0\cdot q,1 \cdot q, \ldots, (p-1)\cdot q$).

For $a=t$ we similarly get solutions for those $b$ that are multiples of $p$ below $n$ ($q$ many).

In all, I get $n +1 + p +q$ keys from these $4$ cases.

Related Question