I don't understand why the inverse is this? my question is related to matrix inverting and Hill cipher(you don't have to know what it is to help me)
My teacher gave me an example. First we have a matrix (the key matrix) that multiplied by a vector of letters is another vector with the previous letters encrypted. To decrypt it you need the inverse of the key matrix and then multiply it by the vector of the encrypted letters, thus you get the vector of the decrypted letters (the real message)
Well, this is the matrix, the key matrix that I have to multiply the vectors of letters by and get the encrypted message.
$$ \left[
  \begin{array}{ c c }
     22&27&18 \\
     18&28&5  \\
     4&17&1
  \end{array} \right]
$$
However, when I try to invert it using multiple calculators on the internet and even programming languages (e.g. Ruby) I get a matrix (the inverted one) with a lot of 0.decimals numbers. Not whole numbers
Why am I expecting to get whole numbers? Because my teacher gave me the inverse. This is it:
$$ \left[
  \begin{array}{ c c }
     1&18&8 \\
     2&8&11  \\
     20&24&14
  \end{array} \right]
$$
I don't get something like this one. I know the inverse matrix is unique, but then who is wrong? Calculators bring on the same matrix, however, the matrix my teacher gave is the right matrix, because it can decrypt the encrypted message well, so it must be the good one.
Not to forget to tell you, that the inverse is the matrix mod 29. 
Any idea on how I could get to the same matrix as my teacher? Thanks a lot.
 A: By Cramer's rule, each coefficient of the inverse matrix is the determinant of a submatrix divided by the determinant $D$ of the original matrix. Here $D=15\pmod{29}$, whose inverse is $2$ mod $29$, hence the coefficients of the inverse matrix are twice the determinants of submatrices, that is, integers mod $29$. 
Note that since $29$ is a prime, every integer which is not $0$ mod $29$ has an integer inverse hence the only case when this can fail is when the determinant is $0$ mod $29$, and then there is no inverse matrix anyway. 
A: You could use Maple to find the inverse of some matrix. You just write the command Inverse(A) mod n. The instructions can be found here.
To find the inverse of a matrix in the field of integers mod a prime number $p$, you proceed in an analogue way as you calculate the inverse of a matrix. The usual formula can be found, for example, here.
The only thing that you need to do is to find $1/\det(A)$ in the field $\Bbb{Z}_p$, i.e. solve the equation $\det(A) \cdot x =1$ in $\Bbb{Z}_p$, and instead of dividing the entries of $A^*$ with the determinant of $A$, you multiply the entries of $A$ with $x$, the solution of the previous equation in $\Bbb{Z}_p$.
A: Since this is an integer array, it has a rational inverse, i.e.
$$\eqalign{
A &=
\left[
\begin{array}{r}
22 & 27 & 18 \\
18 & 28 & 5 \\
4 & 17 & 1 \\
\end{array}
\right]
\quad\implies\quad 
A^{-1} &=
{\frac{1}{2292}}\left[
\begin{array}{r}
-57 & 279 & -369 \\
2 & -50 & 214 \\
194 & \color{red}{-266} & 130 \\
\end{array}
\right]
}$$
and due to the wonders of modulo arithmetic over a prime field, each rational component will correspond to a positive integer in the field, e.g.
$$\eqalign{
&\left(\frac{1}{2292}\right){\rm mod}\,29 = 1
 \quad\qquad\big({\rm via\,Euclidean\,algorithm}\big) \\
&\Big(-266\Big)\,{\rm mod}\,29 = 24 \\
&\left(\frac{-266}{2292}\right){\rm mod}\,29 = 1\cdot 24 = \color{red}{24} \\
}$$
and therefore $$\eqalign{
&A^{-1}\,{\rm mod}\,29 =
\left[
\begin{array}{r}
1 & 18 & 8 \\
2 & 8 & 11 \\
20 & \color{red}{24} & 14 \\\end{array}
\right]
\\
}$$
