Originally Posted by

**culturalreference** Informally, people generally use modular arithmetic in cryptography because it creates a scenario in which one way is solvable in polynomial time (this is the stuff that the two people who are sharing information have to do) and the other way is generally thought to be intractable (this is the stuff that anyone who wants to steal the information has to do). So, modular arithmetic makes it so it's easy enough to communicate information but super hard to steal the information from the outside. The reason for this is, usually, breaking a code that uses modular arithmetic requires being able to factor large numbers in order to find primitive roots or multiplicative inverses, and there is no polynomial time algorithm for factoring.

there's a decent explanation of Diffie Hellman on wikipedia, too, if you want some more information on what exactly is going on.