Version 0 of primeCheckFermat

Updated 2012-09-26 17:42:14 by rwm

rwm -- I thought the primes page was getting too crowded so I added this a s new page. My intent on adding this was to help teach the math and a simeleTcl implementation of the algorithm. I might belong in a cookbook of useful recipees.

Warning - Note that It only checks 'a'=2 which will include some 'liars'. It could be changed to check other a values as well.

References:

  1. http://en.wikipedia.org/wiki/Fermat_primality_test

Dependencies:

  1. a modular exponentiation function
proc primeCheckFermat {p} {
  ## based on fermats little theorem
  ## a**(p-1) == 1
  ## for a in the interval [1,p-1]

  if {[binaryModExpo 2 $p $p] == 2} {
    # possible prime (or fermat liar)
    return 1
  } else {
    #puts stderr "failed fermat check ..."
    # not possible
    return 0
  }
}