ECE 646 Lecture 5. Mathematical Background: Modular Arithmetic

Similar documents
ECE 646 Lecture 5. Motivation: Mathematical Background: Modular Arithmetic. Public-key ciphers. RSA keys. RSA as a trap-door one-way function

Integers and Division

MATH 433 Applied Algebra Lecture 4: Modular arithmetic (continued). Linear congruences.

MONOALPHABETIC CIPHERS AND THEIR MATHEMATICS. CIS 400/628 Spring 2005 Introduction to Cryptography

Public Key Cryptography

Discrete Mathematics GCD, LCM, RSA Algorithm

Math.3336: Discrete Mathematics. Primes and Greatest Common Divisors

Math.3336: Discrete Mathematics. Primes and Greatest Common Divisors

CS 5319 Advanced Discrete Structure. Lecture 9: Introduction to Number Theory II

CPSC 467b: Cryptography and Computer Security

Lecture 5: Arithmetic Modulo m, Primes and Greatest Common Divisors Lecturer: Lale Özkahya

Ma/CS 6a Class 1. Course Details

Number Theory and Group Theoryfor Public-Key Cryptography

COMP239: Mathematics for Computer Science II. Prof. Chadi Assi EV7.635

Public Key Encryption

COT 3100 Applications of Discrete Structures Dr. Michael P. Frank

Mathematical Foundations of Cryptography

ECE596C: Handout #11

Topics in Cryptography. Lecture 5: Basic Number Theory

Introduction to Public-Key Cryptosystems:

Elementary Number Theory MARUCO. Summer, 2018

2.3 In modular arithmetic, all arithmetic operations are performed modulo some integer.

CISC-102 Fall 2017 Week 6

CSE 311: Foundations of Computing. Lecture 12: Two s Complement, Primes, GCD

Number Theory Notes Spring 2011

cse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications

ICS141: Discrete Mathematics for Computer Science I

Congruence Classes. Number Theory Essentials. Modular Arithmetic Systems

Review. CS311H: Discrete Mathematics. Number Theory. Computing GCDs. Insight Behind Euclid s Algorithm. Using this Theorem. Euclidian Algorithm

Ch 4.2 Divisibility Properties

basics of security/cryptography

Number theory. Myrto Arapinis School of Informatics University of Edinburgh. October 9, /29

CPE 776:DATA SECURITY & CRYPTOGRAPHY. Some Number Theory and Classical Crypto Systems

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications

Proofs. Methods of Proof Divisibility Floor and Ceiling Contradiction & Contrapositive Euclidean Algorithm. Reading (Epp s textbook)

Cryptography. monoalphabetic. Ciphers. New Cipher Types. Keyword Cipher. Further subdivisions:...

Sets. We discuss an informal (naive) set theory as needed in Computer Science. It was introduced by G. Cantor in the second half of the nineteenth

Ma/CS 6a Class 2: Congruences

NUMBER THEORY AND CODES. Álvaro Pelayo WUSTL

Introduction to Cryptography CS 355 Lecture 3

Chapter 4 Finite Fields

Elementary Number Theory Review. Franz Luef

The Euclidean Algorithm and Multiplicative Inverses

CSC 474 Information Systems Security

Basic elements of number theory

Basic elements of number theory

CSE 311 Lecture 13: Primes and GCD. Emina Torlak and Kevin Zatloukal

Algorithms CMSC Basic algorithms in Number Theory: Euclid s algorithm and multiplicative inverse

NET 311D INFORMATION SECURITY

Number Theory & Modern Cryptography

3 The fundamentals: Algorithms, the integers, and matrices

Lecture 4: Number theory

The set of integers will be denoted by Z = {, -3, -2, -1, 0, 1, 2, 3, 4, }

CS483 Design and Analysis of Algorithms

Introduction to Number Theory. The study of the integers

CS250: Discrete Math for Computer Science

Section Summary. Division Division Algorithm Modular Arithmetic

Introduction to Cryptography. Lecture 6

This is a recursive algorithm. The procedure is guaranteed to terminate, since the second argument decreases each time.

Introduction to Cybersecurity Cryptography (Part 5)

Chapter 8 Public-key Cryptography and Digital Signatures

Lecture Notes. Advanced Discrete Structures COT S

Number Theory and Cryptography

NOTES ON SIMPLE NUMBER THEORY

CS March 17, 2009

Cryptography. P. Danziger. Transmit...Bob...

Fall 2017 September 20, Written Homework 02

Finite Fields. Mike Reiter

Notes. Number Theory: Applications. Notes. Number Theory: Applications. Notes. Hash Functions I

4 Number Theory and Cryptography

Classical Cryptography

CPSC 467: Cryptography and Computer Security

CMPUT 403: Number Theory

MTH 346: The Chinese Remainder Theorem

W3203 Discrete Mathema1cs. Number Theory. Spring 2015 Instructor: Ilia Vovsha. hcp://

Introduction to Number Theory

Number Theory. CSS322: Security and Cryptography. Sirindhorn International Institute of Technology Thammasat University CSS322. Number Theory.

Lecture 10: HMAC and Number Theory

The Vigenère cipher is a stronger version of the Caesar cipher The encryption key is a word/sentence/random text ( and )

MATH 501 Discrete Mathematics. Lecture 6: Number theory. German University Cairo, Department of Media Engineering and Technology.

INTEGERS. In this section we aim to show the following: Goal. Every natural number can be written uniquely as a product of primes.

RSA Key Generation. Required Reading. W. Stallings, "Cryptography and Network-Security, Chapter 8.3 Testing for Primality

Number Theory. Modular Arithmetic

CS2800 Questions selected for fall 2017

Number Theory: Applications. Number Theory Applications. Hash Functions II. Hash Functions III. Pseudorandom Numbers

Iterated Encryption and Wiener s attack on RSA

With Question/Answer Animations. Chapter 4

Number Theory and Algebra: A Brief Introduction

Ma/CS 6a Class 2: Congruences

CIS 551 / TCOM 401 Computer and Network Security

Congruence of Integers

Candidates must show on each answer book the type of calculator used. Only calculators permitted under UEA Regulations may be used.

4 Powers of an Element; Cyclic Groups

Clock Arithmetic and Euclid s Algorithm

ENEE 457: Computer Systems Security. Lecture 5 Public Key Crypto I: Number Theory Essentials

An Introduction to Cryptography

8 Primes and Modular Arithmetic

Cryptography. pieces from work by Gordon Royle

Course 2BA1: Trinity 2006 Section 9: Introduction to Number Theory and Cryptography

Introduction to Sets and Logic (MATH 1190)

Transcription:

ECE 646 Lecture 5 Mathematical Background: Modular Arithmetic

Motivation: Public-key ciphers

RSA as a trap-door one-way function PUBLIC KEY message ciphertext M C = f(m) = M e mod N C M = f -1 (C) = C d mod N PRIVATE KEY N = P Q P, Q - large prime numbers e d 1 mod ((P-1)(Q-1))

RSA keys PUBLIC KEY PRIVATE KEY { e, N } { d, P, Q } P, Q: N: e: d: P, Q - large prime numbers N = P Q gcd(e, P-1) = 1 and gcd(e, Q-1) = 1 e d 1 mod ((P-1)(Q-1))

Mini-RSA keys PUBLIC KEY PRIVATE KEY { e, N } { d, P, Q } P, Q: N: P = 5 Q = 11 N = P Q = 55 e: gcd(e, 5-1) = 1 and gcd(e, 11-1) = 1 e=3 d: 3 d 1 mod 40 d=27

Mini-RSA as a trap-door one-way function PUBLIC KEY message ciphertext M=2 C = f(2) = 2 3 mod 55 = 8 C=8 M = f -1 (C) = 8 27 mod 55 = 2 PRIVATE KEY N = 5 11 5, 11 - prime numbers 3 27 1 mod ((5-1)(11-1))

Basic definitions

General Notation Z integers - there exists - belongs to - for all! - there exists unique - does not belong to

Divisibility a b a divides b a is a divisor of b a b iff c Z such that b = c a a b a does not divide b a is not a divisor of b

True or False? -3 18 14 7 7 63-13 65 14 21 14 14 0 63 7 0-5 0 0 0

Prime vs. composite numbers An integer p 2 is said to be prime if its only positive divisors are 1 and p. Otherwise, p is called composite.

See Prime or composite? 9 15 7 2 13 103 1117 1239 1427 The Prime Pages: prime number research, records, and resources by Chris Caldwell http://www.utm.edu/research/primes

Greatest common divisor Greatest common divisor of a and b, denoted by gcd(a, b), is the largest positive integer that divides both a and b. d = gcd (a, b) iff 1) d a and d b 2) if c a and c b then c d

gcd (8, 44) = gcd (-15, 65) = gcd (45, 30) = gcd (31, 15) = gcd (0, 40) = gcd (121, 169) =

Relatively prime integers Two integers a and b are relatively prime or co-prime if gcd(a, b) = 1

Properties of the greatest common divisor gcd (a, b) = gcd (a-kb, b) for any k Z

Quotient and remainder Given integers a and n, n>0! q, r Z such that a = q n + r and 0 r < n q quotient r remainder (of a divided by n) q = a n = a div n r = a - q n = a = a mod n a n n =

32 mod 5 = -32 mod 5 =

Integers coungruent modulo n Two integers a and b are congruent modulo n (equivalent modulo n) written a b iff a mod n = b mod n or a = b + kn, k Z or n a - b

Laws of modular arithmetic

Rules of addition, subtraction and multiplication modulo n a + b mod n = ((a mod n) + (b mod n)) mod n a - b mod n = ((a mod n) - (b mod n)) mod n a b mod n = ((a mod n) (b mod n)) mod n

9 13 mod 5 = 25 25 mod 26 =

Laws of modular arithmetic Regular addition a+b = a+c iff b=c Regular multiplication If a b = a c and a 0 then b = c Modular addition a+b a+c (mod n) iff b c (mod n) Modular multiplication If a b a c (mod n) and gcd (a, n) = 1 then b c (mod n)

Modular Multiplication: Example 18 42 (mod 8) 6 3 6 7 (mod 8) 3 7 (mod 8) x 6 x mod 8 0 1 2 3 4 5 6 7 0 6 4 2 0 6 4 2 x 5 x mod 8 0 1 2 3 4 5 6 7 0 5 2 7 4 1 6 3

Algorithms

Euclid s Algorithm for computing gcd(a,b) i q i r i r i+1 = r i-1 mod r i -2-1 0 1 q -1 q 0 q 1 r -2 = max(a, b) r -1 = min(a, b) r 0 r 1 q i = r i-1 r i t-1 t q t-1 r t-1 = gcd(a, b) r t =0 r i+1 = r i-1 - q i r i

Properties of the greatest common divisor gcd (a, b) = gcd (a-kb, b) = gcd(b, a-kb) for any k Z gcd (r i-1, r i ) = gcd(r i, r i-1 - q i r i ) = gcd(r i, r i+1 ) for any q i Z

Euclid s Algorithm Example: gcd(36, 126) i -2-1 0 1 q i q -1 = 3 q 0 = 2 q 1 r i r -2 = max(a, b) =126 r -1 = min(a, b) =36 r 0 = 18 = gcd(36, 126) r 1 = 0 r i+1 = r i-1 mod r i q i = r i-1 r i r i+1 = r i-1 - q i r i

Multiplicative inverse modulo n The multiplicative inverse of a modulo n is an integer [!!!] x such that a x 1 (mod n) The multiplicative inverse of a modulo n is denoted by a -1 mod n (in some books a or a * ). According to this notation: a a -1 1 (mod n)

Extended Euclid s Algorithm (1) r i = x i a + y i n i q i r i x i y i q i = r i-1-2 -1 0 1 q -1 = n/a q 0 q 1 r -2 = n r -1 = a r 0 r 1 x -2 =0 x -1 =1 x 0 x 1 y -2 =1 y -1 =0 y 0 y 1 r i r i+1 = r i-1 - q i r i x i+1 = x i-1 - q i x i y i+1 = y i-1 - q i y i t-1 t q t-1 r t-1 r t =0 x t-1 x t y t-1 y t r t-1 = x t-1 a + y t-1 n

Extended Euclid s Algorithm (2) r t-1 = x t-1 a + y t-1 n r t-1 = x t-1 a + y t-1 n x t-1 a (mod n) If r t-1 = gcd (a, n) = 1 then x t-1 a 1 (mod n) and as a result x t-1 = a -1 mod n

Extended Euclid s Algorithm for computing z = a -1 mod n i q i r i x i q i = r i-1-2 -1 0 1 q -1 = n/a q 0 q 1 r -2 = n r -1 = a r 0 r 1 x -2 =0 x -1 =1 x 0 x 1 r i r i+1 = r i-1 - q i r i x i+1 = x i-1 - q i x i t-1 t q t-1 r t-1 = 1 r t =0 x t-1 = a -1 mod n x t = ±n Note: If r t-1 1 the inverse does not exist

Extended Euclid s Algorithm Example z = 20-1 mod 117 i q i r i x i q i = r i-1-2 -1 0 1 2 3 4 q -1 = 5 q 0 = 1 q 1 = 5 q 2 = 1 q 3 = 2 r -2 = 117 r -1 = 20 r 0 = 17 r 1 = 3 r 2 = 2 r 3 = 1 r 4 = 0 x -2 = 0 x -1 = 1 r i+1 = r i-1 - q i r i x 0 =-5 x i+1 = x i-1 - q i x i x 1 = 6 x 2 = -35 x 3 = 41 = 20-1 mod 117 x 4 = -117 r i Check: 20 41 mod 117 = 1

Motivation Breaking ciphers

Key: Historical ciphers Affine Cipher Key = (k 1, k 2 ) k 1, k 2 [0, 25], gcd (k 1, 26)=1 Encryption transformation: c i = f(m i ) = k 1 m i + k 2 mod 26 Decryption transformation: m i = f -1 (c i ) = k -1 1 (c i - k 2 ) mod 26

Coding characters into numbers A 0 B 1 C 2 D 3 E 4 F 5 G 6 H 7 I 8 J 9 K 10 L 11 M 12 N 13 O 14 P 15 Q 16 R 17 S 18 T 19 U 20 V 21 W 22 X 23 Y 24 Z 25

Key: Historical ciphers Affine Cipher Example (1) Key = (k 1, k 2 ) = (3, 11) 3, 11 [0, 25], gcd (3, 26)=1 Encryption transformation: c i = f(m i ) = 3 m i + 11 mod 26 Decryption transformation: k -1 1 = 3-1 mod 26 = 9 because 3 9 mod 26 = 1 m i = f -1 (c i ) = 9 (c i - 11) mod 26

Historical ciphers Affine Cipher Example (2) coding encryption decoding N 13 3 13 + 11 mod 26 = 24 Y S 18 3 18 + 11 mod 26 = 13 N A 0 3 0 + 11 mod 26 = 11 L

Historical ciphers Affine Cipher Example (3) coding decryption decoding Y 24 9 (24 11) mod 26 = 13 N N 13 9 (13 11) mod 26 = 18 S L 11 9 (11 11) mod 26 = 0 A

Ciphertext: Breaking the affine cipher (1) Step 1: Establish a relative frequency of letters in the ciphertext FMXVE DKAPH FERBN DKRXR SREFM ORUDS DKDVS HVUFE DKAPR KDLYE VLRHH RH A B C D E F G H I J K L M N O P Q R S T U V W X Y Z R - 8 D - 7 E, H, K - 5

Most frequent single letters Average frequency in a random string of letters: 1 = 0.038 = 3.8% 26 Average frequency in a long English text: E 13% T, N, R, I, O, A, S 6%-9% D, H, L 3.5%-4.5% C, F, P, U, M, Y, G, W, V 1.5%-3% B, X, K, Q, J, Z < 1%

Breaking the affine cipher (2) Step 2: Assuming the relative frequency of letters in the corresponding message, derive the corresponding equations Assumption: Most frequent letters in the message: E and T Corresponding equations: E R T D 4 17 19 3 f(e) = R f(t) = D f(4) = 17 f(19) = 3

Breaking the affine cipher (3) Step 3: Solving a set of equations for unknowns k 1 and k 2 f(4) = 17 f(19) = 3 4 k 1 + k 2 17 (mod 26) 19 k 1 + k 2 3 (mod 26) 15 k 1-14 (mod 26) 15 k 1 12 (mod 26)

Solving equations of the form a x b mod n (linear congruences) The equation a x b mod n has 1. one solution iff gcd(a, n) = 1 x = a -1 b (mod n) 2. no solutions iff d = gcd(a, n) 1, and d b 3. d solutions iff d = gcd(a, n) 1, and d b The solutions are x 0, x 0 + n/d, x 0 + 2 n/d, x 0 + 3 n/d,, x 0 + (d-1) n/d, where x 0 = (a/d) -1 (b/d) (mod n/d)

Solving equations of the form a x b mod n (linear congruences) Case 1: Case 2: 0 x n 0 n Case 3: n/d n/d x 0 0 n/d n