Skip to content

Implementation of Miller Rabin Primality testing algorithm. If n is prime, the algorithm always returns “prime”. If n is composite, the algorithm with a probability of at least 1/2 returns “composite”.

Notifications You must be signed in to change notification settings

AyanPahari/Miller-Rabin-Test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Miller-Rabin-Test

Input

An odd integer n ≥ 3.

Output

If n is prime, the algo always returns “prime”. If n is composite, the algo with probability at least 1/2 returns “composite”.

Algorithm

STEP 0: Check if n = a^b for integers a, b ≥ 2. If so, return “composite”.

STEP 1: Select a ∈ {1, 2, . . . , n − 1} uniformly at random. Compute a^(n−1)mod n. If this is not 1, then return “composite”.

STEP 2: Let n − 1 = 2^(k)*t, where t is odd. Compute a^t mod n, a^2t mod n, a^4t mod n, a^8t mod n, . . . , until a 1 is seen. If the number before 1 is not −1, then return “composite”; else return “prime”.

About

Implementation of Miller Rabin Primality testing algorithm. If n is prime, the algorithm always returns “prime”. If n is composite, the algorithm with a probability of at least 1/2 returns “composite”.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages