๐Ÿ”ข Miller-Rabin Primality Test

Probabilistic primality testing โ€” O(k ยท logยฒn) per witness โ† All Visualizations

Input

Slow Fast
โ€”

Witnesses

Enter a number and press Test to begin.

โš™๏ธ Decompose nโˆ’1

Write nโˆ’1 = 2หขยทd (d odd). This exposes the 2-adic structure needed for squaring.

โ€”

๐ŸŽฏ Witness Test

For witness a: compute x = aแตˆ mod n. Square up to s times. Must hit 1 or nโˆ’1 at the right step โ€” otherwise โ†’ COMPOSITE.

๐Ÿ“Š Accuracy

Each round catches composites with prob โ‰ฅ 3/4 (Rabin). After k=5 rounds: error โ‰ค 4โปโต < 0.1%. Used in RSA key generation.