Stuck on an affine cipher exercise I'm tired and can't seem to get the right answer for the following exercise:


  Alice sends a message to Bob, but he doesn't know the key. He knows only that the first two plaintext letters are C and R.
  
  
  The ciphertext is turgifsfsferbi.
  The plaintext is cryptananalyst.
  


The first two plaintext letters are ${\rm C} = 2$ and ${\rm R} = 17$, while the corresponding ciphertext letters are ${\rm T} = 19$ and ${\rm U} = 20$.  The encryption formula is $f(x) = ax+b$, so we have: 

\begin{aligned}
19 &amp;= \phantom{0}2a+b \\
20 &amp;= 17a+b,
\end{aligned}

which I solved to get $-1=-15a \implies a=15$
and $b=3$.

For decryption, we use the formula $f(c)=a^{-1}(c-b) \bmod 26$.  The inverse of $a=15$ modulo $26$ is $a^{-1} = 7$, so for the first ciphertext letter I get:

$$7 \times (19-3) \bmod 26 = 7 \times 16 \bmod 26 = 8 = {\rm I} \ne {\rm C}.$$

So where is my mistake?
If I'm reading your question right, you've made two simple math mistakes:


The solution to $-1 \equiv -15a \pmod{26}$ isn't $a = 15$; it's $a \equiv 15^{-1} \pmod{26}$, or $a = 7$.
I'm not sure where you got $b = 3$, but it's not correct, either.  The right solution, using the correct value of $a = 7$, is $b = 19 - 2a = 19 - 14 = 5$.


(FWIW, using the incorrect value $a = 15$ should've given you either $b = 15$ or $b = 25$, depending on which of the two original congruences you plugged the wrong $a$ into.)

With the correct values of $a$ and $b$, your decryption formula works just fine: $a^{-1} = 7^{-1} \equiv 15 \pmod{26}$, so:

\begin{aligned}
15 \times (19 - 5) &amp;\equiv \phantom{0}2 \pmod{26} \\
15 \times (20 - 5) &amp;\equiv 17 \pmod{26}.
\end{aligned}

Both of your mistakes seem like simple lapses of concentration.  Maybe you just need to take a break from your homework and go get some sleep first.