Beispiel #1
0
  constexpr outer()
    {
      if (m_x.value() != 0)
	throw 0;
      m_x.m_value = integer{1}.value();
      if (m_x.value() != 1)
	throw 0;
    }
Beispiel #2
0
/** \overload c_str_len(integer const&) */
inline
size_t
c_str_len(
    integer const& i
)
{
    return i.length();
}
Beispiel #3
0
inline
size_t
PANTHEIOS_c_str_len_name_(
    integer const& i
)
{
    return i.length();
}
Beispiel #4
0
// --------------------------------------------------------------------------
void
der::encode (
 io::output& output,
 integer const& value
)
// --------------------------------------------------------------------------
{
  std::string contents;

  contents.resize( value.MinEncodedSize(CryptoPP::Integer::SIGNED) );
  value.Encode(
   reinterpret_cast<byte*>(const_cast<char*>(contents.data())),
   contents.size(),
   CryptoPP::Integer::SIGNED
  );

  ber::encode_tag(output, value.tag(), false);
  ber::encode_length(output, contents.size());
  output.write(contents);
}
Beispiel #5
0
std::pair<integer, integer> integer::divide(integer R, const integer& D)
{	if(D == (integer)0 ) throw new std::overflow_error("Division by zero!");
	integer R_initial = R;
	integer Q = 0;
	integer guess = 1;
	integer test;
	//std::stack<integer> stack;
	size_t guess_p = 0;
	if(D > R) return std::pair<integer, integer>(Q, R);
	
	while((D << guess_p) <= R)
	{	//stack.push(guess << guess_p);
		//std::cout << (guess << guess_p) << std::endl;
		guess_p = guess_p+std::numeric_limits<unsigned int>::digits;
		//guess = guess << (size_t)std::numeric_limits<unsigned int>::digits; //bitshift it up by a whole digit
	}
	//guess = stack.top();
	//std::cout << guess << std::endl;
	
	while(guess_p < std::numeric_limits<unsigned int>::max())
	{	test = (D << guess_p);
		if(test <= R)
		{	Q = (Q + (guess << guess_p));
			R = (R - test);
		}
		--guess_p;
	}
	
	
	/*
	while(!stack.empty())
	{	guess = stack.top();
		stack.pop();
		assert(guess.data.back() == 1U);
		guess.data.back() = guess.data.back()<< (std::numeric_limits<unsigned int>::digits -1); //bitshift high digit up by 31 (nominally) bits
		for(size_t i = 0; i <= (std::numeric_limits<unsigned int>::digits - 1); ++i)
		{	test = guess * D;
			//std::cout << guess << std::endl;
			if(test <= R)
			{	Q = Q + guess;
				R = R - test;
				//test = guess * D;
			}
			guess.data.back() = guess.data.back()>>1; //bitshift back down 1 bit.
	}	}
	*/

	assert(R<D);
	Q.minimize();
	R.minimize();
	return std::pair<integer, integer>(Q, R);
}
 static integer abs(const integer &x){
     return x.abs();
 }
Beispiel #7
0
		static integer add(integer i1, integer i2){  // Wertkopien von i1 und i2
		// return integer(i1.i + i2.i); // alternativ und explizit: Konstruktor-Aufruf
		   return i1.get()+i2.get();    // Umwandlung int nach integer, Aufruf Konstruktor implizit
		}
Beispiel #8
0
std::size_t integer_hasher::hash(const integer& v) {
    std::size_t seed(0);

    combine(seed, v.value());
    return seed;
}