BigIntegerAlgorithms.hh 826 B

12345678910111213141516171819202122232425
  1. #ifndef BIGINTEGERALGORITHMS_H
  2. #define BIGINTEGERALGORITHMS_H
  3. #include "BigInteger.hh"
  4. /* Some mathematical algorithms for big integers.
  5. * This code is new and, as such, experimental. */
  6. // Returns the greatest common divisor of a and b.
  7. BigUnsigned gcd(BigUnsigned a, BigUnsigned b);
  8. /* Extended Euclidean algorithm.
  9. * Given m and n, finds gcd g and numbers r, s such that r*m + s*n == g. */
  10. void extendedEuclidean(BigInteger m, BigInteger n,
  11. BigInteger &g, BigInteger &r, BigInteger &s);
  12. /* Returns the multiplicative inverse of x modulo n, or throws an exception if
  13. * they have a common factor. */
  14. BigUnsigned modinv(const BigInteger &x, const BigUnsigned &n);
  15. // Returns (base ^ exponent) % modulus.
  16. BigUnsigned modexp(const BigInteger &base, const BigUnsigned &exponent,
  17. const BigUnsigned &modulus);
  18. #endif