Number Theory.

Slides:



Advertisements
Similar presentations
22C:19 Discrete Structures Integers and Modular Arithmetic
Advertisements

BY : Darshana Chaturvedi.  INTRODUCTION  RSA ALGORITHM  EXAMPLES  RSA IS EFFECTIVE  FERMAT’S LITTLE THEOREM  EUCLID’S ALGORITHM  REFERENCES.
22C:19 Discrete Math Integers and Modular Arithmetic Fall 2010 Sukumar Ghosh.
Number Theory and Cryptography
and Factoring Integers (I)
CSE 321 Discrete Structures Winter 2008 Lecture 8 Number Theory: Modular Arithmetic.
1 Section 2.5 Integers and Algorithms. 2 Euclidean algorithm for finding gcd Where L is a larger number, and S is a smaller number, to find gcd(L,S):
Theory I Algorithm Design and Analysis (9 – Randomized algorithms) Prof. Dr. Th. Ottmann.
Data Representation in Computers
Computer Arithmetic: Binary, Octal and Hexadecimal Presented by Frank H. Osborne, Ph. D. © 2005 ID 2950 Technology and the Young Child.
Codes, Ciphers, and Cryptography-RSA Encryption
1 Introduction to Codes, Ciphers, and Cryptography Michael A. Karls Ball State University.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
Fall 2002CMSC Discrete Structures1 Let us get into… Number Theory.
BY MISS FARAH ADIBAH ADNAN IMK
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 3): The Fundamentals: Algorithms, the.
Mathematics of Cryptography Part I: Modular Arithmetic
MATH 224 – Discrete Mathematics
Module :MA3036NI Cryptography and Number Theory Lecture Week 7
RSA and its Mathematics Behind
CompSci 102 Discrete Math for Computer Science February 16, 2012 Prof. Rodger.
Implementing RSA Encryption in Java
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 31.
Modular Arithmetic with Applications to Cryptography Lecture 47 Section 10.4 Wed, Apr 13, 2005.
Elements of Coding and Encryption Continuation 1.
RSA Prepared by: SITI ZAINAH ADNAN
Copyright © Zeph Grunschlag, Basic Number Theory Zeph Grunschlag.
RSA and its Mathematics Behind July Topics  Modular Arithmetic  Greatest Common Divisor  Euler’s Identity  RSA algorithm  Security in RSA.
22C:19 Discrete Structures Integers and Modular Arithmetic Fall 2014 Sukumar Ghosh.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
POON TENG HIN.  RSA  Shamir’s Three-Pass Protocol  Other issues.
CS Modular Division and RSA1 RSA Public Key Encryption To do RSA we need fast Modular Exponentiation and Primality generation which we have shown.
Module #9 – Number Theory 1/5/ Algorithms, The Integers and Matrices.
Ch1 - Algorithms with numbers Basic arithmetic Basic arithmetic Addition Addition Multiplication Multiplication Division Division Modular arithmetic Modular.
Basic Number Theory.
Chapter 1 Algorithms with Numbers. Bases and Logs How many digits does it take to represent the number N >= 0 in base 2? With k digits the largest number.
Ch04-Number Theory and Cryptography 1. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic.
Number Theory Lecture 1 Text book: Discrete Mathematics and its Applications, 7 th Edition.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Chapter 3 The Fundamentals: Algorithms, the integers, and matrices Section 3.4: The integers and division Number theory: the part of mathematics involving.
1 Solve it with the Computer Rick Spillman CSCE 115 Spring 2013 Lecture 12.
Agenda Review:  Relation Properties Lecture Content:  Divisor and Prime Number  Binary, Octal, Hexadecimal Review & Exercise.
Number Theory. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic principles of divisibility,
Number Systems.
Encryption Take 2: Practical details
Public Key Cryptography
Public Key Encryption Major topics The RSA scheme was devised in 1978
Public Key Encryption.
NUMBER SYSTEMS.
David Kauchak CS52 – Spring 2016
Mathematics of Cryptography
CS 2210:0001Discrete Structures Modular Arithmetic and Cryptography
Advanced Algorithms Analysis and Design
RSA Preliminaries.
Number-Theoretic Algorithms (UNIT-4)
Introduction to Number Theory
MATH301- DISCRETE MATHEMATICS Copyright © Nahid Sultana Dr. Nahid Sultana Chapter 4: Number Theory and Cryptography.
FATİH SULTAN MEHMET VAKIF UNIVERSITY Faculty of Engineering & Architecture Computer Engineering Department MAT217E - DİSCRETE STRUCTURES Slides for a.
University of Gujrat Department of Computer Science
Number Theory (Chapter 7)
Number Theory.
Modular Arithmetic and the RSA Cryptosystem
CSE 321 Discrete Structures
Copyright © Zeph Grunschlag,
Divisibility and Modular Arithmetic
The RSA Public-Key Encryption Algorithm
Presentation transcript:

Number Theory

Importance of Number Theory Before the dawn of computers, many viewed number theory as last bastion of “pure math” which could not be useful and must be enjoyed only for its aesthetic beauty. No longer the case. Number theory is crucial for encryption algorithms. Of utmost importance to everyone from Bill Gates, to the CIA, to Osama Bin Laden.

Divisors DEF: Let a, b and c be integers such that a = b ·c . Then b and c are said to divide (or are factors) of a, while a is said to be a multiple of b (as well as of c). The pipe symbol “|” denotes “divides” so the situation is summarized by: b | a  c | a .

Divisors. Examples A: 77 | 7: false bigger number can’t divide smaller positive number 7 | 77: true because 77 = 7 · 11 24 | 24: true because 24 = 24 · 1 0 | 24: false, only 0 is divisible by 0 24 | 0: true, 0 is divisible by every number (0 = 24 · 0)

Prime Numbers DEF: A number n  2 prime if it is only divisible by 1 and itself. A number n  2 which isn’t prime is called composite. Q: Which of the following are prime? 0,1,2,3,4,5,6,7,8,9,10

Primality Testing Prime numbers are very important in encryption schemes. Essential to be able to verify if a number is prime or not. It turns out that this is quite a difficult problem. First try: boolean isPrime(integer n) if ( n < 2 ) return false for(i = 2 to n /2) if( i |n ) // “divides”! not disjunction return false return true

Greatest Common Divisor Relatively Prime DEF Let a,b be integers, not both zero. The greatest common divisor of a and b (or gcd(a,b) ) is the biggest number d which divides both a and b. Equivalently: gcd(a,b) is smallest number which divisibly by any x dividing both a and b. DEF: a and b are said to be relatively prime if gcd(a,b) = 1, so no prime common divisors.

Greatest Common Divisor Relatively Prime gcd(11,77) = 11 gcd(33,77) = 11 gcd(24,36) = 12 gcd(24,25) = 1. Therefore 24 and 25 are relatively prime. NOTE: A prime number are relatively prime to all other numbers which it doesn’t divide.

Euclidean Algorithm m , n gcd(m,n) integer euclid(pos. integer m, pos. integer n) x = m, y = n while(y > 0) r = x mod y x = y y = r return x Copyright © Zeph Grunschlag, 2001-2002.

Euclidean Algorithm. Example gcd(244,117): By definition  244 and 117 are rel. prime. Step r = x mod y x y - 244 117 1 244 mod 117 = 10 10 2 117 mod 10 = 7 7 3 10 mod 7 = 3 4 7 mod 3 = 1 5 3 mod 1=0 Copyright © Zeph Grunschlag, 2001-2002.

Modular Arithmetic There are two types of “mod” (confusing): the mod function Inputs a number a and a base b Outputs a mod b a number between 0 and b –1 inclusive This is the remainder of ab Similar to Java’s % operator. the (mod) congruence Relates two numbers a, a’ to each other relative some base b a  a’ (mod b) means that a and a’ have the same remainder when dividing by b

mod function Similar to Java’s “%” operator except that answer is always positive. E.G. -10 mod 3 = 2, but in Java –10%3 = -1. 113 mod 24 a mod b = a - c * b use -5 mod 2 then -5/2 = -2.5,becomes -2 then -5 mod 2 = -5 - (-2) * 2 = -5 - (-4) = -1

mod function A: Compute 113 mod 24: -29 mod 7

Modular arithmetic harder examples Q: Compute the following. 3071001 mod 102 (-45 · 77) mod 17

Modular arithmetic harder examples Using multiplication rules, before multiplying (or exponentiating) can reduce modulo 102: 3071001 mod 102  3071001 (mod 102)  11001 (mod 102)  1 (mod 102). Therefore, 3071001 mod 102 = 1.

Modular arithmetic harder examples A: Use the previous identities to help simplify: Similarly, before taking sum can simplify modulo 11: Therefore, the answer is 0.

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

Simple Encryption Variations on the following have been used to encrypt messages for thousands of years. Convert a message to capitals. Think of each letter as a number between 1 and 26. Apply an invertible modular function to each number. Convert back to letters (0 becomes 26).

Letter  Number Conversion Table D E F G H I J K L M 1 2 3 4 5 6 7 8 9 10 11 12 13 N O P Q R S T U V W X Y Z 14 15 16 17 18 19 20 21 22 23 24 25 26

Encryption example Let the encryption function be f (a) = (3a + 9) mod 26 Encrypt “Stop Thief” STOP THIEF (capitals) 19,20,15,16 20,8,9,5,6 14,17,2,5 17,7,10,24,1 NQBE QGJXA

g (a) = 9 (a - 9) mod 26 = (9a – 3) mod 26 Decryption example Decryption works the same, except that you apply the inverse function. EG: Find the inverse of f (a) = (3a + 9) mod 26 If we didn’t have to deal with mod 26, inverse would be g (a) = 3-1 (a - 9) We’ll see that since gcd(3,26) = 1, the inverse of 3 is actually well defined modulo 26 and is the number 9. This gives: g (a) = 9 (a - 9) mod 26 = (9a – 3) mod 26

Public Key Cryptography How can Alice send a secret message to Bob if Bob cannot send a secret key to Alice? ALICE BOB My public key is: 13890580304018329082310291802198210923810830129823019128092183021398301292381320498068029809347849394598178479388287398457923893848928823748283829929384020010924380915809283290823823

RSA Rivest – Shamir – Adelman n = pq. p, q are large primes Choose e relatively prime to (p-1)(q-1) Find d, k such that de + k(p-1)(q-1) = 1 by Euclid’s Algorithm Publish e as the encryption key, d is kept private as the decryption key

Message protocol Bob Alice Precompute p, q, n, e, d Publish e, n Read e, n from Bob’s public site To send message M, compute C = Me mod n Send C to Bob Compute Cd to decode message M

RSA Cryptography m e mod N N = 4559, e = 13. Smiley Transmits: “Last name Smiley” L A S T N A M E S M I L E Y 1201 1920 0014 0113 0500 1913 0912 0525 120113 mod 4559, 192013 mod 4559, … 2853 0116 1478 2150 3906 4256 1445 2462 N = 97·47 Convert white space to 00

RSA Cryptography N = 4559, d = 3397 2853 0116 1478 2150 3906 4256 1445 2462 28533397 mod 4559, 01163397 mod 4559, … 1201 1920 0014 0113 0500 1913 0912 0525 L A S T N A M E S M I L E Y

Decryption de = 1 + k(p-1)(q-1) Cd  (Me)d= Mde = M1 + k(p-1)(q-1) (mod n) Cd M (Mp-1)k(q-1)  M (mod p) Cd M (Mq-1)k(p-1)  M (mod q) Hence Cd  M (mod pq)

Representations of Integers Example: What is the base 8 expansion of (12345)10 ? First, divide 12345 by 8: 12345 = 81543 + 1 1543 = 8192 + 7 192 = 824 + 0 24 = 83 + 0 3 = 80 + 3 The result is: (12345)10 = (30071)8.

Binary Number System The system has only 2 symbols (0,1) The base of the system is “2” Examples of binary numbers: (101,111 , 100.001) Binary number system is used in representing all characters and symbols by using Standard Code as: ASCII (7 bits = 128 characters) ANSI (8 bits = 256 characters) UNICODE (16 bits = 65536 characters)

Octal Number System The system has 8 symbols (0,1,2,3,4,5,6,7) The base of the system = 8 Examples of octal numbers: (171, 11.4 , 512) To find the value of octal number in our decimal system you should take care of the difference between the 2 bases. The number (17)8 is not (17) in decimal

Setting UNIX Access Rights UNIX access rights are assigned to every file and directory on the server. Rights have the form: drwxrwxrwx d means if it is a directory or not r means read w means write x means execute There are three sets of rwx rights. These are for you, for those in your group and for everyone else. Each letter is one bit.

Properties of Hexadecimal A hexadecimal number is exactly one-half of a byte. Since a byte can be from 0-255 in decimal, it also can be from #00 to #FF in hexadecimal. Use the pound sign (#) as a prefix for hexadecimal numbers. Binary and hexadecimal numbers carry to the other half of the same byte at the same time.

Uses of Hexadecimal On the Internet, documents are written in HTML, the hypertext markup language. All colors on computers are a combination of three colors; red, blue and green; known as RGB. In HTML, you set the values of RGB using hexadecimal numbers. The form for a color is: #RRGGBB

Conversion between number systems Converting from any number to decimal Converting from decimal to any number system Converting from binary to octal and hexadecimal Converting from octal to hexadecimal system Converting from any number system to another

Conversion from decimal to other system (fraction part) We can use the successive multiplication by the new base (2 in case of converting to binary system) till having no fraction The integer numbers (from top to bottom) are forming the fraction number in the new number system What is the value of (0.125)10 in binary? fraction integer 0 0.25 2*0.125 0 0.5 2*0.25 1 0.0 2*0.5 The result is: (0.001)2

Conversion between Octal and binary Octal number system uses 8(23) symbols where binary number system uses 2 (21) symbols Each octal digit will be converted to 3 consecutive digits to convert it to binary system Each 3 consecutive binary digits will be converted to 1 octal digit to convert it to octal system Ex: What is the value of (705.3)8 inbinary? (705.3)8 = 111 000 101 . 011 = (111000101.011)2 Ex: What is the value of (1100110.1001)2 in octal? (1100110.1001)2 = (001 100 110 . 100 100)2 = (1 4 6 . 4 4)8 = (146.44)8

Addition of Integers How do we (humans) add two integers? Example: 7583 + 4932 1 1 1 carry 1 2 5 1 5 1 1 carry Binary expansions: (1011)2 + (1010)2 ( )2 1 1 1

2’s Complement Fixes the non-uniqueness of zero problem Adding mixed signs still easy No cycle overflow (pre-computed) Java’s approach (under the hood) Same fixed length k , sign convention, and definition of positive numbers as with 1’s complement Represent numbers with -2(k-1)  x < 2(k-1) EG. Java’s byte ranges from -128 to +127 Copyright © Zeph Grunschlag, 2001-2002.