UCT Algorithm Circle: Number Theory

Similar documents
COMPSCI 230 Discrete Math Prime Numbers January 24, / 15

COP 4516: Math for Programming Contest Notes

Lecture Notes, CSE 232, Fall 2014 Semester

1 Elementary number theory

Applied Cryptography and Network Security

Euclid's Algorithm. MA/CSSE 473 Day 06. Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm

Math Introduction to Advanced Mathematics

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Univ. of Illinois Due Wednesday, Sept 13, 2017 Prof. Allen

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

! Addition! Multiplication! Bigger Example - RSA cryptography

CS/COE 1501 cs.pitt.edu/~bill/1501/ More Math

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

Introduction to Programming in C Department of Computer Science and Engineering\ Lecture No. #02 Introduction: GCD

CSCE 110: Programming I

Lab 1: Cipher Fundamentals

Integers and Mathematical Induction

Section A Arithmetic ( 5) Exercise A

Lecture 7 Number Theory Euiseong Seo

Conditionals !

Creating a new data type

Programming Techniques in Computer Algebra

Ngày 9 tháng 12 năm Discrete Mathematics Lecture-15

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

Lecture 8 Mathematics

Lab 1: Cipher Fundamentals

36 Modular Arithmetic

1 Elementary number theory

Rational numbers as decimals and as integer fractions

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Prepared by Sa diyya Hendrickson. Package Summary

Chapter 1 An Introduction to Computer Science. INVITATION TO Computer Science 1

Elementary number theory

Python lab session 1

r=1 The Binomial Theorem. 4 MA095/98G Revision

CS669 Network Security

Package VeryLargeIntegers

Algorithmic number theory Cryptographic hardness assumptions. Table of contents

Davenport University ITS Lunch and Learn February 2, 2012 Sneden Center Meeting Hall Presented by: Scott Radtke

Course Learning Outcomes for Unit I. Reading Assignment. Unit Lesson. UNIT I STUDY GUIDE Number Theory and the Real Number System

15-110: Principles of Computing, Spring Problem Set 3 (PS3) Due: Friday, February 9 by 2:30PM on Gradescope

Math 302 Introduction to Proofs via Number Theory. Robert Jewett (with small modifications by B. Ćurgus)

Chapter 4. Number Theory. 4.1 Factors and multiples

ICT 6541 Applied Cryptography. Hossen Asiful Mustafa

Programming Training

Modular Arithmetic. Marizza Bailey. December 14, 2015

Admin ENCRYPTION. Admin. Encryption 10/29/15. Assignment 6. 4 more assignments: Midterm next Thursday. What is it and why do we need it?

Overview. Public Key Algorithms I

CITS3211 FUNCTIONAL PROGRAMMING. 7. Lazy evaluation and infinite lists

HIGH PERFORMANCE ELLIPTIC CURVE CRYPTO-PROCESSOR FOR FPGA PLATFORMS

RSA System setup and test

Assertions & Verification & Example Loop Invariants Example Exam Questions

Structured programming

CS Network Security. Nasir Memon Polytechnic University Module 7 Public Key Cryptography. RSA.

CS 310 Advanced Data Structures and Algorithms

Definition MATH Benjamin V.C. Collins, James A. Swenson MATH 2730

Public-Service Announcements

Assertions & Verification Example Exam Questions

Secure understanding of multiplication of whole numbers by 10, 100 or 1000.

1 / 43. Today. Finish Euclid. Bijection/CRT/Isomorphism. Fermat s Little Theorem. Review for Midterm.

Exercise 1.1. Page 1 of 22. Website: Mobile:

COMPUTER SCIENCE TRIPOS

Number Theory Open, Round 1 Test #101

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

CS116 - Module 5 - Accumulative Recursion

- 0 - CryptoLib: Cryptography in Software John B. Lacy 1 Donald P. Mitchell 2 William M. Schell 3 AT&T Bell Laboratories ABSTRACT

Chapter 3 Public Key Cryptography

Introduction to Modular Arithmetic

Discrete Mathematics SECOND EDITION OXFORD UNIVERSITY PRESS. Norman L. Biggs. Professor of Mathematics London School of Economics University of London

Public Key Algorithms

CS3233 Competitive i Programming

Addis Ababa University, Amist Kilo July 5, 2011 Algorithms and Programming for High Schoolers. Lab 2

Lecture 3 Algorithms with numbers (cont.)

Module 2 Congruence Arithmetic pages 39 54

COMPUTER SCIENCE TRIPOS

ECE G205 Fundamentals of Computer Engineering Fall Exercises in Preparation to the Midterm

3/22/17. Admin. Assignment 6 ENCRYPTION. David Kauchak CS52 Spring Survey: How is the class going? Survey: respondents. 24 total respondents

Congruence Arithmetic

Virtual Lab 5 Solution: Chinese Remainder Theorem and Euler's Theorem

Public-Service Announcements

Problem Solving for Intro to Computer Science

Lemma (x, y, z) is a Pythagorean triple iff (y, x, z) is a Pythagorean triple.

Prime Factorization. Jane Alam Jan. 1 P a g e Document prepared by Jane Alam Jan

Administrivia. Last modified: Fri Aug 25 10:59: CS61B: Lecture #2 1

Ch 3.4 The Integers and Division

Names and Functions. Chapter 2

x= suppose we want to calculate these large values 1) x= ) x= ) x=3 100 * ) x= ) 7) x=100!

Odd-Numbered Answers to Exercise Set 1.1: Numbers

Topic 10 Part 2 [474 marks]

Comp 182 Data Structures Sample Midterm Examination

Least Common Multiple (LCM)

RSA (material drawn from Avi Kak Lecture 12, Lecture Notes on "Computer and Network Security" Used in asymmetric crypto.

Understanding Cryptography A Textbook for Students and Practitioners by Christof Paar and Jan Pelzl. Chapter 6 Introduction to Public-Key Cryptography

4 PKI Public Key Infrastructure

Discrete Mathematics Lecture 4. Harper Langston New York University

Mathematics. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

A nice outline of the RSA algorithm and implementation can be found at:

02157 Functional Programming Lecture 2: Functions, Basic Types and Tuples

Class Book. Anita Straker, Tony Fisher, Rosalyn Hyde, Sue Jennings and Jonathan Longstaffe

A.1 Numbers, Sets and Arithmetic

Transcription:

UCT Algorithm Circle: 7 April 2011

Outline Primes and Prime Factorisation 1 Primes and Prime Factorisation 2 3 4

Some revision (hopefully) What is a prime number? An integer greater than 1 whose only factors are itself and 1 2, 3, 5, 7, 11, 13, 17, 19, 23, 29... Non-primes are called composite

Some revision (hopefully) What is a prime number? An integer greater than 1 whose only factors are itself and 1 2, 3, 5, 7, 11, 13, 17, 19, 23, 29... Non-primes are called composite

Some revision (hopefully) What is a prime number? An integer greater than 1 whose only factors are itself and 1 2, 3, 5, 7, 11, 13, 17, 19, 23, 29... Non-primes are called composite

Fundamental Theorem of Arithmetic Any integer greater than 1 can be written as a unique product of prime numbers 6936 = 2 3 3 1 17 2 1200 = 2 4 3 1 5 2

Fundamental Theorem of Arithmetic Any integer greater than 1 can be written as a unique product of prime numbers 6936 = 2 3 3 1 17 2 1200 = 2 4 3 1 5 2

Finding primes the slow way Check for factors! def isprime(x): prime = True for factor in range(2, x): if x % factor == 0: prime = False return prime Can be improved by only checking for factors up to square root of number

Finding primes the slow way Check for factors! def isprime(x): prime = True for factor in range(2, x): if x % factor == 0: prime = False return prime Can be improved by only checking for factors up to square root of number

Sieve of Eratosthenes: a mnemonic Sift the Twos and sift the Threes, The Sieve of Eratosthenes. When the multiples sublime, The numbers that remain are Prime.

Sieve of Eratosthenes Invented by Eratosthenes, Greece, c. 200 BC Quickly find all primes up to a limit x Assume 2 to x are prime Take next known prime, and eliminate its multiples from the list Continue for all numbers on the list The remaining numbers are prime!

Sieve of Eratosthenes Invented by Eratosthenes, Greece, c. 200 BC Quickly find all primes up to a limit x Assume 2 to x are prime Take next known prime, and eliminate its multiples from the list Continue for all numbers on the list The remaining numbers are prime!

Implementation def sieve(x): isprime = [False] * (x + 1) for n in range(2, x + 1): if isprime[n] == True: for multiple in range(2 * n, x + 1, n): isprime[multiple] = False allprimes = [] for n in range(2, x + 1): if isprime[n]: allprimes.append(n) return allprimes

Modification to prime factorise Instead of storing False, store a factor To find a prime factors of n, look up n in the list Divide n by this factor, and look up this new value in the list Continue until the resultant value is 1

Outline Primes and Prime Factorisation 1 Primes and Prime Factorisation 2 3 4

Introduction Common example: a clock Numbers wrap around after some modulus Similar to remainder after division 9 + 4 = 13 1 (mod 12) % operator in Python and other languages

Introduction Common example: a clock Numbers wrap around after some modulus Similar to remainder after division 9 + 4 = 13 1 (mod 12) % operator in Python and other languages

Introduction Common example: a clock Numbers wrap around after some modulus Similar to remainder after division 9 + 4 = 13 1 (mod 12) % operator in Python and other languages

Addition and subtraction Work as expected Just add or subtract remainders, then find new remainder Holds for all real numbers

Addition and subtraction Work as expected Just add or subtract remainders, then find new remainder Holds for all real numbers

Multiplication Multiply remainders, then find new remainder Holds for all integers Division is possible, but complicated

Multiplication Multiply remainders, then find new remainder Holds for all integers Division is possible, but complicated

Multiplication Multiply remainders, then find new remainder Holds for all integers Division is possible, but complicated

Outline Primes and Prime Factorisation 1 Primes and Prime Factorisation 2 3 4

Greatest common divisor The largest factor that will divide two numbers Written GCD(a, b) GCD(9, 12) = 3

By prime factorisation Product of all the common prime factors 6936 = 2 3 3 1 17 2 1200 = 2 4 3 1 5 2 GCD(6936, 1200) = 2 3 3 1 = 24 Prime factorisation is expensive for large numbers Try GCD(2305843009213693951, 2147483647) by hand!

By prime factorisation Product of all the common prime factors 6936 = 2 3 3 1 17 2 1200 = 2 4 3 1 5 2 GCD(6936, 1200) = 2 3 3 1 = 24 Prime factorisation is expensive for large numbers Try GCD(2305843009213693951, 2147483647) by hand!

Euclidean Algorithm Described by Euclid c. 300 BC, but not invented by him GCD(a, b) = GCD(b, a mod b) GCD(a, 0) = a Efficient Number of steps required for completion is never more than five times the number of digits (base 10) of the smaller number Usually much faster

Euclidean Algorithm Described by Euclid c. 300 BC, but not invented by him GCD(a, b) = GCD(b, a mod b) GCD(a, 0) = a Efficient Number of steps required for completion is never more than five times the number of digits (base 10) of the smaller number Usually much faster

Euclidean Algorithm Described by Euclid c. 300 BC, but not invented by him GCD(a, b) = GCD(b, a mod b) GCD(a, 0) = a Efficient Number of steps required for completion is never more than five times the number of digits (base 10) of the smaller number Usually much faster

Efficiency of Euclidean Algorithm

Recursive implementation def gcd(a, b): if b == 0: return a else: return gcd(b, a % b)

Outline Primes and Prime Factorisation 1 Primes and Prime Factorisation 2 3 4

Related reading Euler s Sieve More on modular arithmetic Extended Euclidean Algorithm Fermat s Little Theorem

In the lab Primes and Prime Factorisation Implement a function to prime factorise any given number Implement a Sieve of Eratosthenes Modify it to return the prime factors of all numbers up to the limit