cse 311 foundations of computing i

19
CSE 311 Foundations of Computing I Lecture 10 Divisibility and Modular Arithmetic Autumn 2011 Autumn 2011 CSE 311 1

Upload: geneva

Post on 06-Jan-2016

20 views

Category:

Documents


0 download

DESCRIPTION

CSE 311 Foundations of Computing I. Lecture 10 Divisibility and Modular Arithmetic Autumn 2011. Announcements. Reading assignments Today: 4.1-4.2 7 th Edition 3.4, 3.6 up to p. 227 6 th Edition 2.4, 2.5 up to p. 177 5 th Edition Homework 4 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSE 311  Foundations of Computing I

CSE 311 Foundations of Computing I

Lecture 10Divisibility and Modular Arithmetic

Autumn 2011

Autumn 2011 CSE 311 1

Page 2: CSE 311  Foundations of Computing I

Announcements

• Reading assignments– Today:

• 4.1-4.2 7th Edition• 3.4, 3.6 up to p. 227 6th Edition• 2.4, 2.5 up to p. 177 5th Edition

• Homework 4– Coming soon . . .

Autumn 2011 CSE 311 2

Page 3: CSE 311  Foundations of Computing I

Highlights from last lecture

• Set theory and ties to logic• Lots of terminology

• Complement, Universe of Discourse, Cartesian Product, Cardinality, Power Set, Empty Set, N, Z, Z+, Q, R, Subset, Proper Subset, Venn Diagram, Set Difference, Symmetric Difference, De Morgan’s Laws, Distributive Laws

• Bit vector representation of characteristic functions• Bitwise operations for Set operations

Autumn 2011 CSE 311 3

Page 4: CSE 311  Foundations of Computing I

Unix/Linux file permissions

• ls –l drwxr-xr-x ... Documents/

-rw-r--r-- ... file1

• Permissions maintained as bit vectors–Letter means bit is 1 - means bit is 0.

• How is chmod og+r implemented?

Autumn 2011 CSE 311 4

Page 5: CSE 311  Foundations of Computing I

A simple identity

• If x and y are bits: (x y) y = ?

• What if x and y are bit-vectors?

Autumn 2011 CSE 311 5

Page 6: CSE 311  Foundations of Computing I

Private Key Cryptography

• Alice wants to be able to communicate message secretly to Bob so that eavesdropper Eve who hears their conversation, cannot tell what Alice’s message is

• Alice and Bob can get together and privately share a secret key K ahead of time.

Autumn 2011 CSE 311 6

Page 7: CSE 311  Foundations of Computing I

One-time pad

• Alice and Bob privately share random n-bit vector K – Eve does not know K

• Later, Alice has n-bit message m to send to Bob– Alice computes C = m K– Alice sends C to Bob– Bob computes m = C K which is (m K) K

• Eve cannot figure out m from C unless she can guess K

Autumn 2011 CSE 311 7

Page 8: CSE 311  Foundations of Computing I

Russell’s Paradox

S = { x | x x }/

Page 9: CSE 311  Foundations of Computing I

Number Theory (and applications to computing)

• Branch of Mathematics with direct relevance to computing

• Many significant applications– Cryptography– Hashing– Security

• Important tool set

Page 10: CSE 311  Foundations of Computing I

Modular Arithmetic

• Arithmetic over a finite domain• In computing, almost all computations are

over a finite domain

Page 11: CSE 311  Foundations of Computing I

What are the values computed?

public void Test1() { byte x = 250; byte y = 20; byte z = (byte) (x + y); Console.WriteLine(z); }

public void Test2() { sbyte x = 120; sbyte y = 20; sbyte z = (sbyte) (x + y); Console.WriteLine(z); }

Page 12: CSE 311  Foundations of Computing I

Autumn 2011 CSE 311 12

Page 13: CSE 311  Foundations of Computing I

Arithmetic mod 7

• a +7 b = (a + b) mod 7

• a b = (a b) mod 7

+ 0 1 2 3 4 5 6

0

1

2

3

4

5

6

X 0 1 2 3 4 5 6

0

1

2

3

4

5

6

Page 14: CSE 311  Foundations of Computing I

Divisibility

Autumn 2011 CSE 311 14

Integers a, b, with a ≠ 0, we say that a divides b is there is an integer k such that b = ak. The notation a | b denotes a divides b.

Page 15: CSE 311  Foundations of Computing I

Division Theorem

Autumn 2011 CSE 311 15

Let a be an integer and d a positive integer. Then there are unique integers q and r, with 0 ≤ r < d, such that a = dq + r.

q = a div d r = a mod d

Note: r ≥ 0 even if a < 0. Not quite the same as a%d

Page 16: CSE 311  Foundations of Computing I

Modular Arithmetic

Autumn 2011 CSE 311 16

Let a and b be integers, and m be a positive integer. We say a is congruent to b modulo m if m divides a – b. We use the notation a ≡ b (mod m) to indicate that a is congruent to b modulo m.

Page 17: CSE 311  Foundations of Computing I

Modular arithmetic

Autumn 2011 CSE 311 17

Let a and b be integers, and let m be a positive integer. Then a ≡ b (mod m) if and only if a mod m = b mod m.

Page 18: CSE 311  Foundations of Computing I

Modular arithmetic

Autumn 2011 CSE 311 18

Let m be a positive integer. If a ≡ b (mod m) and c ≡ d (mod m), then

• a + c ≡ b + d (mod m) and • ac ≡ bd (mod m)

Page 19: CSE 311  Foundations of Computing I

Example

Autumn 2011 CSE 311 19

Let n be an integer, prove that n2 ≡ 0 (mod 4) or n2 ≡ 1 (mod 4)