FreeBSD/usr.bin/primes/spsp.c
/* Return non-zero if n is a strong pseudoprime to base p. */
Return non-zero if n is a strong pseudoprime to base p.
Return non - zero if n is a strong pseudoprime to base p .
static int
spsp(uint64_t n, uint64_t p)
{
	uint64_t x;
	uint64_t r = n - 1;
	int k = 0;
	while ((r & 1) == 0) {
		k++;
		r >>= 1;
	}
	x = powmod(p, r, n);
	if (x == 1)
		return (1);
	while (k > 0) {
		if (x == n - 1)
			return (1);
		x = powmod(x, 2, n);
		k--;
	}
	return (0);
}
static int spsp ( uint64_t n , uint64_t p ) { uint64_t x ; uint64_t r = n - 1 ; int k = 0 ; while ( ( r & 1 ) == 0 ) { k ++ ; r >>= 1 ; } x = powmod ( p , r , n ) ; if ( x == 1 ) return ( 1 ) ; while ( k > 0 ) { if ( x == n - 1 ) return ( 1 ) ; x = powmod ( x , 2 , n ) ; k -- ; } return ( 0 ) ; }
Return non-zero if n is a strong pseudoprime to base p.
Return non - zero if n is a strong pseudoprime to base p .
/* Compute n - 1 = 2^k * r. */ /* Compute x = p^r mod n.  If x = 1, n is a p-spsp. */ /* Compute x^(2^i) for 0 <= i < n.  If any are -1, n is a p-spsp. */ /* Not a p-spsp. */