CSE 311 Foundations of Computing I Lecture 11 Modular Exponentiation and Primes Autumn 2011 CSE 3111.

Slides:



Advertisements
Similar presentations
CS 202 Epp section ?? Aaron Bloomfield
Advertisements

CSE331: Introduction to Networks and Security Lecture 19 Fall 2002.
The Integers and Division. Outline Division: Factors, multiples Exercise 2.3 Primes: The Fundamental Theorem of Arithmetic. The Division Algorithm Greatest.
22C:19 Discrete Structures Integers and Modular Arithmetic
CSE 311 Foundations of Computing I Lecture 13 Number Theory Autumn 2012 CSE
22C:19 Discrete Math Integers and Modular Arithmetic Fall 2010 Sukumar Ghosh.
CSE115/ENGR160 Discrete Mathematics 03/13/12 Ming-Hsuan Yang UC Merced 1.
Number Theory and Cryptography
CSE115/ENGR160 Discrete Mathematics 03/15/11
CSE 321 Discrete Structures Winter 2008 Lecture 8 Number Theory: Modular Arithmetic.
1 Integers and Division CS/APMA 202 Rosen section 2.4 Aaron Bloomfield.
CSE 321 Discrete Structures Winter 2008 Lecture 10 Number Theory: Primality.
CSE 311 Foundations of Computing I Lecture 12 Primes, GCD, Modular Inverse Spring
Fall 2002CMSC Discrete Structures1 Let us get into… Number Theory.
Integers Number Theory = Properties of Integers
The Fundamentals: Algorithms, Integers, and Matrices CSC-2259 Discrete Structures Konstantin Busch - LSU1.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 2): The Fundamentals: Algorithms, the.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
February 24, 2015Applied Discrete Mathematics Week 4: Number Theory 1 Modular Arithmetic Let a be an integer and m be a positive integer. We denote by.
3.4/3.5 The Integers and Division/ Primes and Greatest Common Divisors Let each of a and b be integers. We say that a divides b, in symbols a | b, provided.
MATH 224 – Discrete Mathematics
Discrete Mathematics CS 2610 March 17, Number Theory Elementary number theory, concerned with numbers, usually integers and their properties or.
CompSci 102 Discrete Math for Computer Science February 16, 2012 Prof. Rodger.
Chapter The Integers and Division Division
Data Security and Encryption (CSE348) 1. Lecture # 12 2.
Foundations of Computing I CSE 311 Fall It’s Boolean algebra again Definition for  based on  Definition for  based on  Complement works like.
Number Theory 이재원 School of Information Technology Sungshin W. University.
Chapter 2 (Part 1): The Fundamentals: Algorithms, the Integers & Matrices The Integers and Division (Section 2.4)
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
22C:19 Discrete Structures Integers and Modular Arithmetic Fall 2014 Sukumar Ghosh.
Foundations of Discrete Mathematics Chapter 4 By Dr. Dalia M. Gil, Ph.D.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
CSE 311 Foundations of Computing I Lecture 14 Euclid’s Algorithm Mathematical Induction Autumn 2012 CSE
Module #9 – Number Theory 1/5/ Algorithms, The Integers and Matrices.
Foundations of Computing I CSE 311 Fall Review: Division Theorem Let a be an integer and d a positive integer. Then there are unique integers q.
15-499Page :Algorithms and Applications Cryptography II – Number theory (groups and fields)
CSE 311: Foundations of Computing Fall 2013 Lecture 12: Primes, GCD, modular inverse.
CSE 311: Foundations of Computing Fall 2013 Lecture 11: Modular arithmetic and applications.
Divisibility and Modular Arithmetic
MA/CSSE 473 Day 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
The Fundamentals: Algorithms, Integers, and Matrices CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
Ch04-Number Theory and Cryptography 1. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic.
MA/CSSE 473 Day 05 More induction Factors and Primes Recursive division algorithm.
Chapter 4 With Question/Answer Animations 1. Chapter Motivation Number theory is the part of mathematics devoted to the study of the integers and their.
Number Theory Lecture 1 Text book: Discrete Mathematics and its Applications, 7 th Edition.
CSE 311 Foundations of Computing I Lecture 12 Modular Arithmetic and Applications Autumn 2012 CSE
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division Fermat's little theorem intro.
Chapter 3 The Fundamentals: Algorithms, the integers, and matrices Section 3.4: The integers and division Number theory: the part of mathematics involving.
Number Theory. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic principles of divisibility,
CS 210 Discrete Mathematics The Integers and Division (Section 3.4)
CSE15 Discrete Mathematics 03/15/17
CS 2210:0001Discrete Structures Modular Arithmetic and Cryptography
CMSC Discrete Structures
CSE 311 Foundations of Computing I
MATH301- DISCRETE MATHEMATICS Copyright © Nahid Sultana Dr. Nahid Sultana Chapter 4: Number Theory and Cryptography.
CSE 311 Foundations of Computing I
CSE 311 Foundations of Computing I
CSE 311 Foundations of Computing I
CSE 311: Foundations of Computing
CSE 311 Foundations of Computing I
CSE 321 Discrete Structures
CSE 321 Discrete Structures
CMSC 203, Section 0401 Discrete Structures Fall 2004 Matt Gaston
Copyright © Zeph Grunschlag,
Divisibility and Modular Arithmetic
Presentation transcript:

CSE 311 Foundations of Computing I Lecture 11 Modular Exponentiation and Primes Autumn 2011 CSE 3111

Announcements Reading assignments – Today and Monday: th Edition 3.5, th Edition 2.5, 2.6 up to p th Edition – Wednesday Start on induction Homework 4 – Available now (posted Wednesday night) Autumn 2011CSE 3112

Highlights from last lecture Introduction of modular arithmetic Fumbling with the projector and whiteboard (morning lecture) Autumn 2011CSE 3113 What is the difference between r = a mod d and r ≡ a (mod d) ?

Division Theorem Autumn 2011CSE 3114 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

Modular Arithmetic Autumn 2011CSE 3115 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. 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. 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)

Modular arithmetic Autumn 2011CSE 3116 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.

Example Autumn 2011CSE 3117 Let n be an integer, prove that n 2 ≡ 0 (mod 4) or n 2 ≡ 1 (mod 4)

n-bit Unsigned Integer Representation Represent integer x as sum of powers of 2: If x =  i=0 b i 2 i where each b i ∈ {0,1} then representation is b n-1...b 2 b 1 b 0 99 = = For n = 8: 99: : Autumn 2011CSE 3118 n-1

Signed integer representation Autumn 2011CSE 3119 n-bit signed integers Suppose -2 n-1 < x < 2 n-1 First bit as the sign, n-1 bits for the value 99 = = For n = 8: 99: : Any problems with this representation?

Two’s complement representation Autumn 2011CSE n bit signed integers, first bit will still be the sign bit Suppose 0 ≤ x < 2 n-1, x is represented by the binary representation of x Suppose 0 < x ≤ 2 n-1, -x is represented by the binary representation of 2 n -x 99 = = For n = 8: 99: : Key property: Two’s complement representation of any number y is equivalent to y mod 2 n so arithmetic works mod 2 n

Two’s complement representation Suppose 0 < x ≤ 2 n-1, -x is represented by the binary representation of 2 n -x To compute this: Flip the bits of x then add 1: – All 1’s string is 2 n -1 so Flip the bits of x  replace x by 2 n -1-x Autumn 2011CSE 31111

Basic applications of mod Hashing Pseudo random number generation Simple cipher

Hashing Map values from a large domain, 0…M-1 in a much smaller domain, 0…n-1 Index lookup Test for equality Hash(x) = x mod p Often want the hash function to depend on all of the bits of the data – Collision management

Pseudo Random number generation Linear Congruential method x n+1 = (a x n + c) mod m

Simple cipher Caesar cipher, A = 1, B = 2,... – HELLO WORLD Shift cipher – f(p) = (p + k) mod 26 – f -1 (p) = (p – k) mod 26 f(p) = (ap + b) mod 26

Modular Exponentiation X aa1a1 a2a2 a3a3 a4a4 a5a5 a6a

Exponentiation Compute Compute mod

Fast exponentiation int FastExp(int x, int n){ long v = (long) x; int m = 1; for (int i = 1; i <= n; i++){ v = (v * v) % modulus; m = m + m; Console.WriteLine("i : " + i + ", m : " + m + ", v : " + v ); } return (int)v; }

Program Trace i : 1, m : 2, v : i : 2, m : 4, v : i : 3, m : 8, v : i : 4, m : 16, v : i : 5, m : 32, v : i : 6, m : 64, v : i : 7, m : 128, v : i : 8, m : 256, v : i : 9, m : 512, v : i : 10, m : 1024, v : i : 11, m : 2048, v : 4207 i : 12, m : 4096, v : i : 13, m : 8192, v : i : 14, m : 16384, v : i : 15, m : 32768, v : i : 16, m : 65536, v : 29057

Fast exponentiation algorithm What if the exponent is not a power of two? = The fast exponentiation algorithm computes a n mod p in time O(log n)

Primality An integer p greater than 1 is called prime if the only positive factors of p are 1 and p. A positive integer that is greater than 1 and is not prime is called composite.

Fundamental Theorem of Arithmetic Autumn 2011CSE Every positive integer greater than 1 has a unique prime factorization 48 = = ,523 = 45, ,950 = ,234,567,890 = ,607 3,803

Factorization If n is composite, it has a factor of size at most sqrt(n)

Euclid’s theorem There are an infinite number of primes. Proof by contradiction: Suppose there are a finite number of primes: p 1, p 2,... p n

Distribution of Primes If you pick a random number n in the range [x, 2x], what is the chance that n is prime?

Famous Algorithmic Problems Primality Testing: – Given an integer n, determine if n is prime Factoring – Given an integer n, determine the prime factorization of n

Primality Testing Is the following 200 digit number prime: