Docsity

Understanding the Mod Operator: Binary vs. Congruence Relation, Exercises of Cryptography and System Security

Toggle sidebar
bg1
1/12/06
D-2
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 × nfor 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)
docsity.com
pf3

Partial preview of the text

Download Understanding the Mod Operator: Binary vs. Congruence Relation and more Exercises Cryptography and System Security in PDF only on Docsity!

D-

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 ( x^2 + y + 1) mod (2 m + n )

D-

where all of the variables are integers. In each case, the left-hand term is divided by the right- hand 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) ( x^2 + 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.