Skip to content

Instantly share code, notes, and snippets.

@randombit
Created April 10, 2018 15:41
Show Gist options
  • Save randombit/ed2f4cd9c3781cc40b43f5de277eade3 to your computer and use it in GitHub Desktop.
Save randombit/ed2f4cd9c3781cc40b43f5de277eade3 to your computer and use it in GitHub Desktop.
Miller-Rabin error probabilities
#!/usr/bin/python
from math import log, pow, sqrt
import sys
# Estimate Miller-Rabin error probability based on bitsize (k)
# and number of MR tests (t)
# https://www.math.dartmouth.edu//~carlp/PDF/paper88.pdf
k = int(sys.argv[1])
t = int(sys.argv[2])
if t * 9 > k:
print("invalid k,t")
err = log(1 / (pow(k, 3.0/2) * pow(2,t) * pow(t, -.5) * pow(4, 2-sqrt(t*k)))) / log(2)
print("p(%d,%d) = %.02f" % (k, t, err))
@randombit
Copy link
Author

You need to provide k and t as command line arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment