Skip to content

Instantly share code, notes, and snippets.

@hauleth
Created September 14, 2015 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hauleth/cba01660a83ab8c967a2 to your computer and use it in GitHub Desktop.
Save hauleth/cba01660a83ab8c967a2 to your computer and use it in GitHub Desktop.
fn witness(num: BigInt, a: BigInt, d: &BigInt, s: usize) -> Result {
let mut x = (&a).pow_mod(d, &num);
if x == one() || x == (&num - BigInt::one()) { return Result::Composite }
for _ in 0..s {
x = (&x * &x) % #
if x == one() { return Result::Composite }
if x == (&num - BigInt::one()) { return Result::PropablyPrime }
}
Result::Composite
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment