14.2 Number Theory

Team-Fly

14.2 Number Theory

In contrast to the arithmetic functions, the following number-theoretic member functions do not overwrite the implicit first argument with the result. The reason for this is that with more complex functions it has been shown in practice not to be practical to overwrite, as is the case with simple arithmetic functions. The results of the following functions are thus returned as values rather than as pointers.

start sidebar

Function:

calculate the greatest integer less than or equal to the base-2 logarithm of a LINT object

Syntax:

 const unsigned int LINT::ld (void); 

Input:

implicit argument a

Return:

integer part of the base-2 logarithm of a

Example:

i = a.ld ();

end sidebar

start sidebar

Function:

calculate the greatest common divisor of two LINT objects

Syntax:

 const LINT LINT::gcd (const LINT& b); 

Input:

implicit argument a

second argument b

Return:

gcd (a, b) of the input values

Example:

c = a.gcd (b);

end sidebar

start sidebar

Function:

calculate the multiplicative inverse modulo n

Syntax:

 const LINT LINT::inv (const LINT& n); 

Input:

implicit argument a

modulus n

Return:

multiplicative inverse of a modulo n (if the result is equal to zero, then gcd(a, n) > 1 and the inverse does not exist)

Example:

c = a.inv (n);

end sidebar

start sidebar

Function:

calculate the greatest common divisor of a and b as well as its representation g = ua+vb as a linear combination of a and b

Syntax:

 const LINT LINT::xgcd(const LINT& b,                LINT& u, int& sign_u,                LINT& v, int& sign_v); 

Input:

implicit argument a, second argument b

Output:

Factor u of the representation of gcd (a, b) sign of u in sign_u

factor v of the representation of gcd (a, b) sign of v in sign_v

Return:

gcd(a, b) of the input values

Example:

g = a.xgcd (b, u, sign_u, v, sign_v);

end sidebar

start sidebar

Function:

calculate the least common multiple (lcm) of two LINT objects

Syntax:

 const LINT LINT::lcm(const LINT& b); 

Input:

implicit argument a

factor b

Return:

lcm(a, b) of the input values

Example:

c = a.lcm (b);

end sidebar

start sidebar

Function:

solution of a system of linear congruences x a mod m, x b mod n,

Syntax:

 const LINT LINT::chinrem(const LINT& m, const LINT& b,                const LINT& n); 

Input:

implicit argument a, modulus m, argument b, modulus n

Return:

solution x of the congruence system if all is ok (Get_Warning_Status() == E_LINT_ERR indicates that an overflow has occurred or that the congruences have no common solution)

Example:

x = a.chinrem (m, b, n);

end sidebar

The friend function chinrem(const int noofeq, LINT** coeff) accepts a vector coeff of pointers to LINT objects, which are passed as coefficients a1, m1, a2, m2, a3, m3,... of a system of linear congruences with "arbitrarily" many equations x ai mod mi, i = 1,..., noofeq (see Appendix B).

start sidebar

Function:

calculation of the Jacobi symbol of two LINT objects

Syntax:

 const int LINT::jacobi (const LINT& b); 

Input:

implicit argument a, second argument b

Return:

Jacobi symbol of the input values

Example:

i = a.jacobi (b);

end sidebar

start sidebar

Function:

calculation of the integer part of the square root of a LINT object

Syntax:

 const LINT LINT::root (void); 

Input:

implicit argument a

Return:

integer part of the square root of the input value

Example:

c = a.root ();

end sidebar

start sidebar

Function:

calculation of the square root modulo a prime p of a LINT object

Syntax:

 const LINT LINT::root (const LINT& p); 

Input:

implicit argument a, prime modulus p > 2

Return:

square root of a if a is a quadratic residue modulo p otherwise 0 (Get_Warning_Status() == E_LINT_ERR indicates that a is not a quadratic residue modulo p)

Example:

c = a.root (p);

end sidebar

start sidebar

Function:

calculation of the square root of a LINT object modulo a prime product p·q

Syntax:

 const LINT LINT::root (const LINT& p, const LINT& q); 

Input:

implicit argument a

prime modulus p > 2, prime modulus q > 2

Return:

square root of a if a is a quadratic residue modulo pq otherwise 0 (Get_Warning_Status() == E_LINT_ERR indicates that a is not a quadratic residue modulo p*q)

Example:

c = a.root (p, q);

end sidebar

start sidebar

Function:

test of whether a LINT object is a square

Syntax:

 const int LINT::issqr(void);, 

Input:

test candidate a as implicit argument

Return:

square root of a if a is a square otherwise 0 if a == 0 or a not a square

Example:

if(0 == (r = a.issqr ())) // ...

end sidebar

start sidebar

Function:

probabilistic primality test of a LINT object

Syntax:

 const int LINT::isprime (void); 

Input:

test candidate a as implicit argument

Return:

1 if a is a "probable" prime

0 otherwise

Example:

if(a.isprime ()) // ...

end sidebar

start sidebar

Function:

calculate the two-part of a LINT object

Syntax:

 const int LINT::twofact (LINT& b); 

Input:

implicit argument a

Output:

b (odd part of a)

Return:

exponent of the odd part of a

Example:

e = a.twofact (b);

end sidebar


Team-Fly


Cryptography in C and C++
Cryptography in C and C++
ISBN: 189311595X
EAN: 2147483647
Year: 2001
Pages: 127

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net