# implementing modular multiplicative inverse.

I wish to implement the clifford cocks algorithm using GMP. In the encryption part: $c_1=t_1+at_1^{-1}\bmod n$. Following $( a b \bmod n ) = ((a \bmod n) \cdot (b \bmod n ))\bmod n$, I took the modular multiplicative inverse of $t_1$, multiplied by $(a \bmod n)$ added it to $(t_1 \bmod n)$ and again took the mod. Please someone suggest where am I going wrong. And is there any alternative approach to it?

• @Jonathan Mckibbin : Please look at my edits including the use of \bmod. And it is uncouth to use an asterisk for ordinary multiplication in MathJax, LaTeX, or the like. – Michael Hardy Mar 3 '15 at 15:41