Professional Documents
Culture Documents
Lecture 11
Lecture 11
Lecture 11
q = a div d r = a mod d
Foundations of
Computing I
Fall 2014
Let a and b be integers, and m be a positive integer. Integers a, b, with a ≠ 0, we say that a divides b if
We say a is congruent to b modulo m if m divides a – b. there is an integer k such that b = ka. The notation
We use the notation a ≡ b (mod m) to indicate that a is a | b denotes “a divides b.”
congruent to b modulo m.
CSE 311: Foundations of Computing Modular Arithmetic: A Property
Let a and b be integers, and let m be a positive
Fall 2013
integer. Then a ≡ b (mod m) if and only if
Lecture 11: Modular arithmetic and applications a mod m = b mod m.
Let m be a positive integer. If a ≡ b (mod m) and Let m be a positive integer. If a ≡ b (mod m) and
c ≡ d (mod m), then a + c ≡ b + d (mod m) c ≡ d (mod m), then ac ≡ bd (mod m)
99 = 64 + 32 + 2 + 1
99 = 64 + 32 + 2 + 1 18 = 16 + 2
18 = 16 + 2
For n = 8:
• For n = 8: 99: 0110 0011
99: 0110 0011 -18: 1001 0010
18: 0001 0010
Any problems with this representation?
Two’s Complement Representation Sign-Magnitude vs. Two’s Complement
n bit signed integers, first bit will still be the sign bit -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
1111 1110 1101 1100 1011 1010 1001 0000 0001 0010 0011 0100 0101 0110 0111
Suppose 0 ≤ < 2 ,
is represented by the binary representation of Sign-Magnitude
Suppose 0 ≤ ≤ 2 ,
− is represented by the binary representation of 2 −
1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111
99 = 64 + 32 + 2 + 1 Two’s complement
18 = 16 + 2
For n = 8:
99: 0110 0011
-18: 1110 1110
• Caesar cipher, A = 1, B = 2, . . . X 1 2 3 4 5 6 a a1 a2 a3 a4 a5 a6
– HELLO WORLD 1 1
2 2
• Shift cipher 3 3
– f(p) = (p + k) mod 26 4 4
– f-1(p) = (p – k) mod 26 5 5
6 6
• More general
– f(p) = (ap + b) mod 26
modular exponentiation mod 7 modular exponentiation mod 7
X 1 2 3 4 5 6 a a1 a2 a3 a4 a5 a6 X 1 2 3 4 5 6 a a1 a2 a3 a4 a5 a6
1 1 2 3 4 5 6 1 1 1 2 3 4 5 6 1 1 1 1 1 1 1
2 2 4 6 1 3 5 2 2 2 4 6 1 3 5 2 2 4 1 2 4 1
3 3 6 2 5 1 4 3 3 3 6 2 5 1 4 3 3 2 6 4 5 1
4 4 1 5 2 6 3 4 4 4 1 5 2 6 3 4 4 2 1 4 2 1
5 5 3 1 6 4 2 5 5 5 3 1 6 4 2 5 5 4 6 2 3 1
6 6 5 4 3 2 1 6 6 6 5 4 3 2 1 6 6 1 6 1 6 1