# Understanding how to perform modular arithmetic

I'm reading a text book about cryptography. The text on RSA encryption uses modular arithmetic. When exercising myself with the materials, I struggled a bit with this.

As far as I understood, when my text book says that $100^3 \equiv 254 \mod 319$, I'm tempted to calculate $(100 * 100 * 100) \% 319$ which indeed yields 254. In this case, I'm using $%$ as in C and many other programming languages: as a 'remainder' operator.

Does this make any mathematical sense? Is this the correct way of performing modular arithmetic?

• if % is what is done in the C language then yes, it is correct. There are many mathematical results for shortcuts for modular arithmetics where you don't have to remember or calculate the whole number – mathreadler Dec 23 '16 at 19:11
• Be sure to understand the relationship between "mod" as a binary operator (remainder) vs. ternary congruence relation, e.g. see this answer and this one by Arturo Magidin. – Bill Dubuque Dec 23 '16 at 19:14
• Yes! Another way to think about it is to think, is $(100^3 - 254)$ divisible by $319$? – Euler_Salter Dec 23 '16 at 19:27
• @mathreadler That would be interesting, since my OS calculator had some troubles calculating $165^{107}$... – mthmulders Dec 23 '16 at 19:30
• For methods of calculating $165^{107}\bmod n$ I recommend that you take a look at what is explained here as well as familiarize yourself with the square-and-multiply algorithm – Jyrki Lahtonen Dec 23 '16 at 19:43