Modular Arithmetic

Before we look at the code in the RSA program example, let's first understand a bit more about modular arithmetic. Modular arithmetic is used in many cryptographic systems, including RSA, DSA, and SSL. The algebraic structure that is used is referred to as Zn , which is the set of nonnegative integers modulo n. Zn consists of the set {0, 1, 2, …, n – 1} along with operators defined for addition and multiplication. Note that Zn is integer arithmetic on a finite circle, not an infinite number line. Zn is sometimes referred to as clock arithmetic, since a twelve hour clock implies Z12 arithmetic.

For example, Z12 would be the set of numbers from 0 to 11, with addition defined much like regular addition, but any result over 11 ...

Get .NET Security and Cryptography now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.