/usr/include/givaro/givintprime.inl is in libgivaro-dev 3.2.13-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #ifndef __GIVARO__PRIMALITY_INL
#define __GIVARO__PRIMALITY_INL
// =================================================================== //
// Givaro : Prime numbers
// Primality tests
// Time-stamp: <29 Jun 05 14:11:07 Jean-Guillaume.Dumas@imag.fr>
// =================================================================== //
#include <math.h>
#include "givaro/givintprime.h"
// =================================================================== //
// Primality tests and factorization algorithms
// =================================================================== //
// =================================================================== //
// Primality tests
// =================================================================== //
template<class RandIter> unsigned int IntPrimeDom::Miller(RandIter& g, const Integer& n) const
{
// Monte Carlo algorithm
// returns 1 : n prime with probability 3/4
// returns 0 : n composite
if (n < 2) return 0;
if (n <= 3) return 1;
IntPrimeDom::Rep t=n-1,a,q;
random(g,a,n);
long s=0;
for( ; !( (int)t & 0x1) ; t>>=1, ++s) { }
powmod(q,a,t,n);
if ( (q==1) || (q == (n-1))) return 1;
// for(;s>1;--s) {
for(;--s>0;) {
q = (q*q) % n;
if (q == (n-1)) return 1;
}
return 0;
}
template<class RandIter>
IntPrimeDom::Rep& IntPrimeDom::test_Lehmann(RandIter& g, Rep& r, const Rep& n) const {
// Monte Carlo algorithm
// returns n-1 : n prime with probability 1/2
// returns 1 : n composite with probability 1/2
// else : n composite
IntPrimeDom::Rep A;
random(g,A,n);
return powmod(r,A,(n-1)/2,n);
}
template<class RandIter>
int IntPrimeDom::Lehmann(RandIter& g, const Rep& n) const
{
if (n < 2) return 0;
if (n <= 3) return 1;
IntPrimeDom::Rep tmp;
IntPrimeDom::test_Lehmann(g,tmp,n);
if (tmp == (n-1))
return 1;
return 0;
}
#endif
|