# How do you solve a system of linear equations in modular arithmetic.

I'm finding a hard time trying to proceed with this cryptography problem:

If i'm given such a system of linear equations:

$3x+5y+7z\equiv3 (mod\ 16)$

$x+4y+13z\equiv5 (mod\ 16)$

$2x+7y+3z\equiv4 (mod\ 16)$

How do i go on finding general solutions for $x, y, z$ ?

• What would you do? – Rol Dec 8 '15 at 13:58
• The same way you would work over the reals. Except that instead of dividing an equation (or a row of the matrix) you need to multiply it with the inverse of the coefficient that you want to replace by a $1$. The caveat is that modulo sixteen the even numbers don't have inverses, so you can only multiply by the inverse of an odd numbers. If the determinant is an odd number, you will do just fine. Also, after each step reduce all the matrix entries modulo 16. – Jyrki Lahtonen Dec 8 '15 at 14:00
• See here for an example modulo 29. That is a prime number, so it was all plain sailing as long as I never tried to divide by 29. After all iin that field 29=0. Here it is a bit more complicated because 16 is not a prime. That means that success is not guaranteed (unless the determinant is odd, but here that is the case and you should be fine). – Jyrki Lahtonen Dec 8 '15 at 14:03
• @JyrkiLahtonen: The first comment alone is actually a full answer. Why not post it that way? – P Vanchinathan Dec 8 '15 at 14:05
• @JyrkiLahtonen Thanks for the simple explanation. Please post it as an answer. – Shubham Kanodia Dec 8 '15 at 14:56

The $2$nd congruence gives $x\equiv -4y-13z+5\pmod{16}$, so you're left with two congruences with two variables:
$$3(-4y-13z+5)+5y+7z\equiv 3\pmod{16}\\2(-4y-13z+5)+7y+3z\equiv 4\pmod{16}$$
$$9y\equiv 36\pmod{16}\\15y+9z\equiv 10\pmod{16}$$
Now divide both sides by $9$ to get $y\equiv 4\pmod{16}$, so $9z\equiv -18\pmod{16}$, so (divide both sides by $9$): $z\equiv -2\equiv 14\pmod{16}$, so $x\equiv 15\pmod{16}$.