Affine Cipher - Pair of plain to cipher text Consider an affine cipher.
  
  The cryptanalyst observed the following plaintext/ciphertext pairs $(p,c)$: $(8,15)$ and $(5,16)$.
  
  
  Recover the key $(a,b)$ used in the encryption system above.
  What is the ciphertext corresponding to the plaintext $p=3$? 
  


For #1, I came to this result:

$$\begin{aligned}
8 \cdot a + b &amp;\equiv 15, \\ 
5 \cdot a + b &amp;\equiv 16 \\
\implies
a &amp;\equiv 17, \\
b &amp;\equiv 9.
\end{aligned}
\pmod{26} $$

For #2, congruence gave me:

$$\begin{aligned}
3a &amp;\equiv -1, \\
\text{which is}\quad 3a &amp;\equiv 25, \\
\implies 3^{-1} &amp;\equiv 27,
\end{aligned}
\pmod{26} $$

not $17$. Am I doing something wrong?
After $3a=-1 \pmod{26}$ note that mod $26$ we have $-1 = 25=51=3\cdot 17$, so $a=17$. 

Alternatively, note that $3\cdot9=27=1$ so we can multiply both sides by $3^{-1}=9$ and $-9=17\pmod{26}$. 

And then $5\cdot17 +b = 9$, and $5\cdot 17=85=7$ and so $b=9$. 

Now substitute $p=3$ in the encryption formula $c=17p+9$ for the final question.