Download presentation
Presentation is loading. Please wait.
1
Number Theory
2
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.
3
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 .
4
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)
5
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
6
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
7
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.
8
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.
9
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,
10
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,
11
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 ab 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
12
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
13
mod function A: Compute 113 mod 24: -29 mod 7
14
Modular arithmetic harder examples
Q: Compute the following. mod 102 (-45 · 77) mod 17
15
Modular arithmetic harder examples
Using multiplication rules, before multiplying (or exponentiating) can reduce modulo 102: mod 102 (mod 102) (mod 102) 1 (mod 102). Therefore, mod 102 = 1.
16
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.
17
Pseudo Random number generation
Linear Congruential method xn+1 = (a xn + c) mod m
18
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).
19
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
20
Encryption example Let the encryption function be
f (a) = (3a + 9) mod 26 Encrypt “Stop Thief” STOP THIEF (capitals) 19,20,15, ,8,9,5,6 14,17,2,5 17,7,10,24,1 NQBE QGJXA
21
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
22
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:
23
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
24
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
25
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 mod 4559, mod 4559, … N = 97·47 Convert white space to 00
26
RSA Cryptography N = 4559, d = 3397 mod 4559, mod 4559, … L A S T N A M E S M I L E Y
27
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)
28
Representations of Integers
Example: What is the base 8 expansion of (12345)10 ? First, divide by 8: 12345 = 8 1543 = 8 192 = 824 + 0 24 = 83 + 0 3 = 80 + 3 The result is: (12345)10 = (30071)8.
29
Binary Number System The system has only 2 symbols (0,1)
The base of the system is “2” Examples of binary numbers: (101,111 , ) 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 = characters)
30
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
31
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.
32
Properties of Hexadecimal
A hexadecimal number is exactly one-half of a byte. Since a byte can be from 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.
33
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
34
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
35
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.125 *0.25 *0.5 The result is: (0.001)2
36
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 = = ( )2 Ex: What is the value of ( )2 in octal? ( )2 = ( )2 = ( )8 = (146.44)8
37
Addition of Integers How do we (humans) add two integers?
Example: 1 1 1 carry 1 2 5 1 5 1 1 carry Binary expansions: (1011) (1010)2 ( )2 1 1 1
38
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,
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.