Esempio n. 1
0
bool InvertibleLUCFunction::Validate(RandomNumberGenerator &rng, unsigned int level) const
{
	bool pass = LUCFunction::Validate(rng, level);
	pass = pass && m_p > Integer::One() && m_p.IsOdd() && m_p < m_n;
	pass = pass && m_q > Integer::One() && m_q.IsOdd() && m_q < m_n;
	pass = pass && m_u.IsPositive() && m_u < m_p;
	if (level >= 1)
	{
		pass = pass && m_p * m_q == m_n;
		pass = pass && RelativelyPrime(m_e, m_p+1);
		pass = pass && RelativelyPrime(m_e, m_p-1);
		pass = pass && RelativelyPrime(m_e, m_q+1);
		pass = pass && RelativelyPrime(m_e, m_q-1);
		pass = pass && m_u * m_q % m_p == 1;
	}
	if (level >= 2)
		pass = pass && VerifyPrime(rng, m_p, level-2) && VerifyPrime(rng, m_q, level-2);
	return pass;
}
Esempio n. 2
0
/**
 * Given target_count number to sample from data_count members
 * find a sampling rate that when used to increment an index 
 * more or less evenly picks modulo data_count.
 * Making the rate relatively prime wrapping means that if an increment
 * wraps back to the beginning of the vector it will find different
 * indices.
 */
size_t SamplingRate(size_t target_count, size_t data_count)
{
  assert( (target_count > 0) && (data_count > 0) );
  size_t rate = 1;

  if (target_count >= data_count)
    return(rate);

  if (target_count < data_count){ 
    rate = (data_count/target_count) + 1;
    while ( (rate<data_count) && !RelativelyPrime (data_count, rate)){
      rate++;
    }
  }
  return(rate);
}
Esempio n. 3
0
	bool IsAcceptable(const Integer &candidate) const {return RelativelyPrime(m_e, candidate-Integer::One());}
Esempio n. 4
0
	bool IsAcceptable(const Integer &candidate) const
	{
		return RelativelyPrime(m_e, candidate+1) && RelativelyPrime(m_e, candidate-1);
	}