SlideShare a Scribd company logo
1 of 18
Bharathiar University
Department of Computer Applications
N.Mohanasundaram
II - MCA
Primality Testing
Introduction
 The primality test provides the probability
of whether or not a large number is
prime.
 Several theorems including Fermat’s
theorem provide idea of primality test.
 Cryptography schemes such as RSA
algorithm heavily based on primality test.
Definitions
 A Prime number is an integer that has no
integer factors other than 1 and itself. On the
other hand, it is called composite number.
 A primality testing is a test to determine
whether or not a given number is prime, as
opposed to actually decomposing the number
into its constituent prime factors (which is
known as prime factorization) Use multiple
points if necessary.
Algorithms
 A Naïve Algorithm
 Pick any integer P that is greater than 2.
 Try to divide P by all odd integers starting from 3
to square root of P.
 If P is divisible by any one of these odd integers,
we can conclude that P is composite.
 The worst case is that we have to go through all
odd number testing cases up to square root of P.
 Time complexity is O(square root of N)
Algorithms (Cont.)
 Fermat’s Theorem
 Given that P is an integer that we would like to test that it is either
a PRIME or not.
 And A is another integer that is greater than zero and less than P.
 From Fermat’s Theorem, if P is a PRIME, it will satisfy this two
equalities:
 A^(p-1) = 1(mod P) or A^(p-1)mod P = 1
 A^P = A(mod P) or A^P mod P = A
 For instances, if P = 341, will P be PRIME?
-> from previous equalities, we would be able to obtain
that:
2^(341-1)mod 341 = 1, if A = 2
Algorithms (Cont.)
 It seems that 341 is a prime number under
Fermat’s Theorem. However, if A is now
equal to 3:
 3^(341-1)mod 341 = 56 !!!!!!!!!
 That means Fermat’s Theorem is not true in
this case!
 ⇒ Time complexity is O(log n) ⇐
Algorithms (Cont.)
 Rabin-Miller’s Probabilistic Primality Algorithm
 The Rabin-Miller’s Probabilistic Primality test was
by Rabin, based on Miller’s idea. This algorithm
provides a fast method of determining of primality
of a number with a controllably small probability
of error.
 Given (b, n), where n is the number to be tested
for primality, and b is randomly chosen in [1, n-1].
Let n-1 = (2^q)*m, where m is an odd integer.
 B^m = 1(mod n)
 ∃i∈[0, q-1] such that b^(m2)^i = -1(mod n)
Algorithm (Cont.)
 If the testing number satisfies either cases, it will be
said as “inconclusive”. That means it could be a prime
number.
 From Fermat’s Theorem, it concludes 341 is a prime
but it is 11 * 31!
 Now try to use Rabin-Miller’s Algorithm.
 Let n be 341, b be 2. then assume:
 q = 2 and m = 85 (since, n -1 = 2^q*m)
 2^85 mod 341 = 32
 Since it is not equal to 1, 341 is composite!
 Time complexity is O(log N)
RSA Algorithm
 The scheme was developed by Rivest,
Shamir, and Adleman.
 The scheme was used to encrypt
plaintext into blocks in order to prevent
third party to gain access to private
message.
RSA in action:
1. Pick two large prime numbers namely p
and q and compute their product and
set it as n.
n = p*q
RSA in action (cont.):
2. Set public key to send the message.
 public key (e, n)
such that: gcd(φ(n), e) = 1; [1<e< φ(n)]
 sender uses public key to encrypt the
message before sending it to the
recipient.
RSA in action (cont.):
3. Retrieve message using private key.
 at the recipient’s side, private key(d, n),
such that ed = 1mod φ(n), need to be
obtained in order to get the original
message through decryption.
Demonstration for RSA:
 Pick 2 primes: p=7, q=17
n = p*q
n = 119
 Compute:
φ(n) = φ(119)
= φ(7*17)
= φ(7) * φ(17)
= 6 * 16
= 96
 Find e such that gcd(φ(n), e) = 1; [1<e< φ(n)]
gcd(e, 96) = 1
e = 5 ⇒ public key(e, n) ⇐
 Find d such that ed = 1mod φ(n)
5d = 1mod96
5d = 96 * k +1, where k is some constant
5d = 96 * 4 + 1, assume k = 4
5d = 385
d = 77 ⇒ private key(d, n) ⇐
Demonstration for Encryption:
! Base on RSA and the result we got !
 Encryption . . . (message = 19)
C = M^e mod n
= 19^5 mod 119
= 2476099 mod 119
= 66 <the original message will be encrypted with the value of 66>
Demonstration for Decryption
! Base on RSA and the result we got !
 Decryption . . .
M = C^d mod n
M = 66^77 mod 119
M = 1.27 * 10^140 mod 119
M = 19 <the original will now be recovered>
Reference:
 An Online Calculator by Ulf Wostner from CCSF
http://wiz.ccsf.edu/~uwostner/calculator/number_theory.p
hp
 Definition of Rabin-Miller’s Probabilistic Primality Testing
http://www.ma.iup.edu/MAA/proceedings/vol1/higgins.pdf
 Definition of Primality Testing
http://mathworld.wolfram.com/AKSPrimalityTest.html
 Primality Test for Applications
http://www-math.mit.edu/phase2/UJM/vol1/DORSEY-
F.PDF
Thank you

More Related Content

What's hot (20)

SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Unit 1
Unit 1Unit 1
Unit 1
 
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITYCS6701 CRYPTOGRAPHY AND NETWORK SECURITY
CS6701 CRYPTOGRAPHY AND NETWORK SECURITY
 
Public Key Cryptography
Public Key CryptographyPublic Key Cryptography
Public Key Cryptography
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Classical encryption techniques
Classical encryption techniquesClassical encryption techniques
Classical encryption techniques
 
Elgamal &amp; schnorr digital signature scheme copy
Elgamal &amp; schnorr digital signature scheme   copyElgamal &amp; schnorr digital signature scheme   copy
Elgamal &amp; schnorr digital signature scheme copy
 
Presentation about RSA
Presentation about RSAPresentation about RSA
Presentation about RSA
 
Daa notes 3
Daa notes 3Daa notes 3
Daa notes 3
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network security
 
Substitution techniques
Substitution techniquesSubstitution techniques
Substitution techniques
 
Diffie hellman key exchange algorithm
Diffie hellman key exchange algorithmDiffie hellman key exchange algorithm
Diffie hellman key exchange algorithm
 
Matrix multiplication
Matrix multiplicationMatrix multiplication
Matrix multiplication
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Diffie-hellman algorithm
Diffie-hellman algorithmDiffie-hellman algorithm
Diffie-hellman algorithm
 
OSI Security Architecture
OSI Security ArchitectureOSI Security Architecture
OSI Security Architecture
 
Rsa rivest shamir adleman
Rsa rivest shamir adlemanRsa rivest shamir adleman
Rsa rivest shamir adleman
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Cs8792 cns - unit iv
Cs8792   cns - unit ivCs8792   cns - unit iv
Cs8792 cns - unit iv
 
Network security cryptography ppt
Network security cryptography pptNetwork security cryptography ppt
Network security cryptography ppt
 

Similar to Primality

Basics of Mathematical Cryptography
Basics of Mathematical CryptographyBasics of Mathematical Cryptography
Basics of Mathematical CryptographyNeha Gupta
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality TestingMohammad Elsheikh
 
2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiouvafopoulos
 
Cs8792 cns - Public key cryptosystem (Unit III)
Cs8792   cns - Public key cryptosystem (Unit III)Cs8792   cns - Public key cryptosystem (Unit III)
Cs8792 cns - Public key cryptosystem (Unit III)ArthyR3
 
RSA final notation change2
RSA final notation change2RSA final notation change2
RSA final notation change2Coleman Gorham
 
Senior Research Final Draft3
Senior Research Final Draft3Senior Research Final Draft3
Senior Research Final Draft3Coleman Gorham
 
Information and network security 33 rsa algorithm
Information and network security 33 rsa algorithmInformation and network security 33 rsa algorithm
Information and network security 33 rsa algorithmVaibhav Khanna
 
Prime Numbers and Their Digital Roots
Prime Numbers and Their Digital RootsPrime Numbers and Their Digital Roots
Prime Numbers and Their Digital RootsIRJET Journal
 
11 Applied_Mathemathics HANDBOOK.pdf
11 Applied_Mathemathics HANDBOOK.pdf11 Applied_Mathemathics HANDBOOK.pdf
11 Applied_Mathemathics HANDBOOK.pdfVipinNegi38
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
The Mathematics of RSA Encryption
The Mathematics of RSA EncryptionThe Mathematics of RSA Encryption
The Mathematics of RSA EncryptionNathan F. Dunn
 
Number_Theory-1 number theory notes for engineering
Number_Theory-1 number theory notes for engineeringNumber_Theory-1 number theory notes for engineering
Number_Theory-1 number theory notes for engineeringrewiko3718
 
Cyber Security Part-3.pptx
Cyber Security Part-3.pptxCyber Security Part-3.pptx
Cyber Security Part-3.pptxRavikumarVadana
 
ch08 modified.pptmodified.pptmodified.ppt
ch08 modified.pptmodified.pptmodified.pptch08 modified.pptmodified.pptmodified.ppt
ch08 modified.pptmodified.pptmodified.ppttahirnaquash2
 

Similar to Primality (20)

Basics of Mathematical Cryptography
Basics of Mathematical CryptographyBasics of Mathematical Cryptography
Basics of Mathematical Cryptography
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality Testing
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou
 
Ch08
Ch08Ch08
Ch08
 
Cs8792 cns - Public key cryptosystem (Unit III)
Cs8792   cns - Public key cryptosystem (Unit III)Cs8792   cns - Public key cryptosystem (Unit III)
Cs8792 cns - Public key cryptosystem (Unit III)
 
RSA final notation change2
RSA final notation change2RSA final notation change2
RSA final notation change2
 
Ch08
Ch08Ch08
Ch08
 
Senior Research Final Draft3
Senior Research Final Draft3Senior Research Final Draft3
Senior Research Final Draft3
 
Information and network security 33 rsa algorithm
Information and network security 33 rsa algorithmInformation and network security 33 rsa algorithm
Information and network security 33 rsa algorithm
 
Prime Numbers and Their Digital Roots
Prime Numbers and Their Digital RootsPrime Numbers and Their Digital Roots
Prime Numbers and Their Digital Roots
 
11 Applied_Mathemathics HANDBOOK.pdf
11 Applied_Mathemathics HANDBOOK.pdf11 Applied_Mathemathics HANDBOOK.pdf
11 Applied_Mathemathics HANDBOOK.pdf
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Eulers totient
Eulers totientEulers totient
Eulers totient
 
The Mathematics of RSA Encryption
The Mathematics of RSA EncryptionThe Mathematics of RSA Encryption
The Mathematics of RSA Encryption
 
Prime number
Prime numberPrime number
Prime number
 
Number_Theory-1 number theory notes for engineering
Number_Theory-1 number theory notes for engineeringNumber_Theory-1 number theory notes for engineering
Number_Theory-1 number theory notes for engineering
 
Cyber Security Part-3.pptx
Cyber Security Part-3.pptxCyber Security Part-3.pptx
Cyber Security Part-3.pptx
 
Slide2
Slide2Slide2
Slide2
 
ch08 modified.pptmodified.pptmodified.ppt
ch08 modified.pptmodified.pptmodified.pptch08 modified.pptmodified.pptmodified.ppt
ch08 modified.pptmodified.pptmodified.ppt
 

Recently uploaded

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Primality

  • 1. Bharathiar University Department of Computer Applications N.Mohanasundaram II - MCA
  • 3. Introduction  The primality test provides the probability of whether or not a large number is prime.  Several theorems including Fermat’s theorem provide idea of primality test.  Cryptography schemes such as RSA algorithm heavily based on primality test.
  • 4. Definitions  A Prime number is an integer that has no integer factors other than 1 and itself. On the other hand, it is called composite number.  A primality testing is a test to determine whether or not a given number is prime, as opposed to actually decomposing the number into its constituent prime factors (which is known as prime factorization) Use multiple points if necessary.
  • 5. Algorithms  A Naïve Algorithm  Pick any integer P that is greater than 2.  Try to divide P by all odd integers starting from 3 to square root of P.  If P is divisible by any one of these odd integers, we can conclude that P is composite.  The worst case is that we have to go through all odd number testing cases up to square root of P.  Time complexity is O(square root of N)
  • 6. Algorithms (Cont.)  Fermat’s Theorem  Given that P is an integer that we would like to test that it is either a PRIME or not.  And A is another integer that is greater than zero and less than P.  From Fermat’s Theorem, if P is a PRIME, it will satisfy this two equalities:  A^(p-1) = 1(mod P) or A^(p-1)mod P = 1  A^P = A(mod P) or A^P mod P = A  For instances, if P = 341, will P be PRIME? -> from previous equalities, we would be able to obtain that: 2^(341-1)mod 341 = 1, if A = 2
  • 7. Algorithms (Cont.)  It seems that 341 is a prime number under Fermat’s Theorem. However, if A is now equal to 3:  3^(341-1)mod 341 = 56 !!!!!!!!!  That means Fermat’s Theorem is not true in this case!  ⇒ Time complexity is O(log n) ⇐
  • 8. Algorithms (Cont.)  Rabin-Miller’s Probabilistic Primality Algorithm  The Rabin-Miller’s Probabilistic Primality test was by Rabin, based on Miller’s idea. This algorithm provides a fast method of determining of primality of a number with a controllably small probability of error.  Given (b, n), where n is the number to be tested for primality, and b is randomly chosen in [1, n-1]. Let n-1 = (2^q)*m, where m is an odd integer.  B^m = 1(mod n)  ∃i∈[0, q-1] such that b^(m2)^i = -1(mod n)
  • 9. Algorithm (Cont.)  If the testing number satisfies either cases, it will be said as “inconclusive”. That means it could be a prime number.  From Fermat’s Theorem, it concludes 341 is a prime but it is 11 * 31!  Now try to use Rabin-Miller’s Algorithm.  Let n be 341, b be 2. then assume:  q = 2 and m = 85 (since, n -1 = 2^q*m)  2^85 mod 341 = 32  Since it is not equal to 1, 341 is composite!  Time complexity is O(log N)
  • 10. RSA Algorithm  The scheme was developed by Rivest, Shamir, and Adleman.  The scheme was used to encrypt plaintext into blocks in order to prevent third party to gain access to private message.
  • 11. RSA in action: 1. Pick two large prime numbers namely p and q and compute their product and set it as n. n = p*q
  • 12. RSA in action (cont.): 2. Set public key to send the message.  public key (e, n) such that: gcd(φ(n), e) = 1; [1<e< φ(n)]  sender uses public key to encrypt the message before sending it to the recipient.
  • 13. RSA in action (cont.): 3. Retrieve message using private key.  at the recipient’s side, private key(d, n), such that ed = 1mod φ(n), need to be obtained in order to get the original message through decryption.
  • 14. Demonstration for RSA:  Pick 2 primes: p=7, q=17 n = p*q n = 119  Compute: φ(n) = φ(119) = φ(7*17) = φ(7) * φ(17) = 6 * 16 = 96  Find e such that gcd(φ(n), e) = 1; [1<e< φ(n)] gcd(e, 96) = 1 e = 5 ⇒ public key(e, n) ⇐  Find d such that ed = 1mod φ(n) 5d = 1mod96 5d = 96 * k +1, where k is some constant 5d = 96 * 4 + 1, assume k = 4 5d = 385 d = 77 ⇒ private key(d, n) ⇐
  • 15. Demonstration for Encryption: ! Base on RSA and the result we got !  Encryption . . . (message = 19) C = M^e mod n = 19^5 mod 119 = 2476099 mod 119 = 66 <the original message will be encrypted with the value of 66>
  • 16. Demonstration for Decryption ! Base on RSA and the result we got !  Decryption . . . M = C^d mod n M = 66^77 mod 119 M = 1.27 * 10^140 mod 119 M = 19 <the original will now be recovered>
  • 17. Reference:  An Online Calculator by Ulf Wostner from CCSF http://wiz.ccsf.edu/~uwostner/calculator/number_theory.p hp  Definition of Rabin-Miller’s Probabilistic Primality Testing http://www.ma.iup.edu/MAA/proceedings/vol1/higgins.pdf  Definition of Primality Testing http://mathworld.wolfram.com/AKSPrimalityTest.html  Primality Test for Applications http://www-math.mit.edu/phase2/UJM/vol1/DORSEY- F.PDF