You are on page 1of 4

A PPENDIX D The Meaning of mod

D.1 THE BINARY OPERATOR mod ............................................................................2 D.1 THE CONGRUENCE RELATION mod..................................................................3

William Stallings Copyright 2006

Supplement to Cryptography and Network Security, Fourth Edition Prentice Hall 2006 ISBN: 0-13-187316-4 http://williamstallings.com/Crypto/Crypto4e.html

1/12/06 The operator mod is used in this book, and in the literature, in two different ways, as a binary operator and as a congruence relation. This appendix explains the distinction and precisely defines the notation used in this book regarding parentheses. This notation is common but, unfortunately, not universal.

D.1 THE BINARY OPERATOR mod


If a is an integer and n is a nonzero integer, we define a mod n to be the remainder when a is divided by n. The integer n is called the modulus, and the remainder is called the residue. Thus, for any integer a, we can always write:

a = a/n n + ( a mod n)

Formally, we define the operator mod as follows:

a mod n = a a/n n

for n 0

As a binary operation, mod takes two integer arguments and returns the remainder. For example, 7 mod 3 = 1. The arguments may be integers, integer variables, or integer variable expressions. For example, all of the following are valid, with the obvious meanings:

7 mod 3 7 mod m x mod 3 x mod m (x2 + y + 1) mod (2m + n)

D-2

1/12/06 where all of the variables are integers. In each case, the left-hand term is divided by the righthand term, and the resulting value is the remainder. Note that if either the left- or right-hand argument is an expression, the expression is parenthesized. The operator mod is not inside parentheses. In fact, the mod operation also works if the two arguments are arbitrary real numbers, not just integers. In this book, we are concerned only with the integer operation.

D.1 THE CONGRUENCE RELATION mod


As a congruence relation, mod expresses that two arguments have the same remainder with respect to a given modulus. For example 7 4 (mod 3) expresses the fact that both 7 and 4 have a remainder of 1 when divided by 3. The following two expressions are equivalent:

a b (mod m)

a mod m = b mod m

Another way of expressing it is to say that the expression a b (mod m) is the same as saying that a b is an integral multiple of m. Again, all the arguments may be integers, integer variables, or integer variable expressions. For example, all of the following are valid, with the obvious meanings:

7 4 (mod 3) x y (mod m) (x2 + y + 1) (a + 1) (mod [m + n])

where all of the variables are integers. Two conventions are used. The congruence sign is . The modulus for the relation is defined by placing the mod operator followed by the modulus in parentheses. D-3

1/12/06 The congruence relation is used to define residue classes. Those numbers that have the same remainder r when divided by m form a residue class (mod m ). There are m residue classes (mod m). For a given remainder r, the residue class to which it belongs consists of the numbers

r, r m , r 2 m, . . .

According to our definition, the congruence

a b (mod m)

signifies that the numbers a and b differ by a multiple of m. Consequently, the congruence can also be expressed in the terms that a and b belong to the same residue class (mod m ).

D-4

You might also like