QtBigInt/src/bigint.h

207 lines
10 KiB
C
Raw Normal View History

2019-07-07 18:37:20 +03:00
//#
2020-01-06 14:16:10 +03:00
//# Copyright (C) 2018-2020 QuasarApp.
2019-07-07 18:37:20 +03:00
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
2019-07-07 18:28:48 +03:00
#ifndef BIGINT_H
#define BIGINT_H
#include "mini-gmp.h"
#include <string>
#include <vector>
2019-07-07 18:37:20 +03:00
#include "minigmp_global.h"
2019-07-07 18:28:48 +03:00
/**
* @brief The BigInt class - c++ minigmp wrapper
*/
2019-07-09 14:11:26 +03:00
class MINIGMPSHARED_EXPORT BigInt
2019-07-07 18:28:48 +03:00
{
mpz_t data;
public:
2019-07-13 16:14:29 +03:00
BigInt();
BigInt(const BigInt& val, int bitCount = -1);
2019-07-12 18:02:08 +03:00
BigInt(const std::string &imput, int base = 10);
BigInt(intMpz val);
2019-07-13 17:49:15 +03:00
BigInt(char item, unsigned int size, int base);
2019-07-07 18:28:48 +03:00
std::string getString(int base = 10) const;
~BigInt();
2019-07-11 14:04:54 +03:00
BigInt& powm(const BigInt &pow, const BigInt &mod);
2019-07-13 16:14:29 +03:00
static BigInt powm(BigInt val, const BigInt & pow, const BigInt &mod);
BigInt& pow(uIntMpz pow);
2019-07-18 16:17:09 +03:00
BigInt& log(int base);
/**
* @brief sizeBits
* @return size of bits in memory
*/
2019-07-11 14:04:54 +03:00
int sizeBits() const;
int sizeBytes() const;
2019-07-18 16:17:09 +03:00
/**
* @brief longBits
* @return current length in Bits of number
2019-07-18 16:17:09 +03:00
*/
int longBits() const;
int longBytes() const;
2019-07-13 16:14:29 +03:00
int sizeType() const;
bool isPrime(bool absalut = false) const;
BigInt& gcd(const BigInt &a, const BigInt &b);
void fromHex(const std::string& hex);
2019-07-11 09:49:56 +03:00
/**
* @brief bigPow10
* @param pow
* @return number 10 ^ pow
*/
2019-07-11 18:39:19 +03:00
static BigInt bigPow10(unsigned short pow);
2019-07-11 09:49:56 +03:00
2019-07-12 22:51:57 +03:00
BigInt& toNegative();
2019-07-09 15:35:24 +03:00
BigInt& operator = (const BigInt& val);
2019-07-12 18:02:08 +03:00
BigInt& operator = (const std::string &imput);
BigInt& operator = (intMpz val);
2019-07-09 15:35:24 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator + ( BigInt left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator + ( intMpz left, BigInt right);
friend BigInt MINIGMPSHARED_EXPORT operator + ( const std::string &left, const BigInt &right);
2019-07-12 18:02:08 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator += ( BigInt &left, intMpz right);
friend BigInt& MINIGMPSHARED_EXPORT operator += ( BigInt &left, const BigInt& right);
friend BigInt& MINIGMPSHARED_EXPORT operator += ( BigInt &left, const std::string &right);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator - ( BigInt left, const std::string &right);
2019-07-12 18:02:08 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator - ( intMpz right, BigInt left);
friend BigInt MINIGMPSHARED_EXPORT operator - ( const std::string &right, const BigInt &left);
2019-07-08 17:41:19 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator-(BigInt val);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator -= ( BigInt &left, intMpz right);
2019-07-12 22:51:57 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator -= ( BigInt &left, const BigInt& right);
friend BigInt& MINIGMPSHARED_EXPORT operator -= ( BigInt &left, const std::string &right);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator / ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( BigInt left, intMpz right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( intMpz left, BigInt right);
friend BigInt MINIGMPSHARED_EXPORT operator / ( const std::string &left, const BigInt &right);
2019-07-07 21:10:53 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator /= ( BigInt &left, intMpz right);
friend BigInt& MINIGMPSHARED_EXPORT operator /= ( BigInt &left, const std::string &right);
friend BigInt& MINIGMPSHARED_EXPORT operator /= ( BigInt &left, const BigInt& right);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator * ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator * ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator * ( BigInt left, intMpz right);
2019-07-12 18:02:08 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator * ( intMpz left, BigInt right);
2019-07-12 18:02:08 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator *= ( BigInt &left, const BigInt& right);
friend BigInt& MINIGMPSHARED_EXPORT operator *= ( BigInt &left, intMpz right);
friend BigInt& MINIGMPSHARED_EXPORT operator *= ( BigInt &left, const std::string &right);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, const std::string &right);
friend BigInt MINIGMPSHARED_EXPORT operator % ( BigInt left, intMpz right);
2019-07-07 21:10:53 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator % ( intMpz left, BigInt right);
friend BigInt MINIGMPSHARED_EXPORT operator % ( const std::string & left, const BigInt &right);
2019-07-07 21:10:53 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator %= ( BigInt &left, intMpz right);
friend BigInt& MINIGMPSHARED_EXPORT operator %= ( BigInt &left, const std::string &right);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator %= ( BigInt &left, const BigInt& right);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator << ( BigInt left, int right);
friend BigInt MINIGMPSHARED_EXPORT operator >> ( BigInt left, int right);
2019-07-09 12:47:39 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator <<= ( BigInt &left, int right);
friend BigInt& MINIGMPSHARED_EXPORT operator >>= ( BigInt &left, int right);
2019-07-09 12:47:39 +03:00
2020-01-08 09:19:09 +03:00
friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator == ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator == ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator == ( intMpz left, const std::string& right);
2019-07-09 12:47:39 +03:00
2020-01-08 09:19:09 +03:00
friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator != ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator != ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator != ( intMpz left, const std::string& right);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator < ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator < ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator < ( intMpz left, const std::string& right);
2019-07-09 12:47:39 +03:00
2020-01-08 09:19:09 +03:00
friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator > ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator > ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator > ( intMpz left, const std::string& right);
2019-07-07 18:28:48 +03:00
2020-01-08 09:19:09 +03:00
friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator <= ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator <= ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator <= ( intMpz left, const std::string& right);
2019-07-09 12:47:39 +03:00
2020-01-08 09:19:09 +03:00
friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, intMpz right);
friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const std::string& str);
friend bool MINIGMPSHARED_EXPORT operator >= ( const std::string& left, const BigInt& right);
friend bool MINIGMPSHARED_EXPORT operator >= ( const BigInt& left, const std::string& right);
friend bool MINIGMPSHARED_EXPORT operator >= ( intMpz left, const std::string& right);
2019-07-07 21:10:53 +03:00
2020-01-08 09:19:09 +03:00
friend bool MINIGMPSHARED_EXPORT operator!(const BigInt& val);
2019-07-07 21:10:53 +03:00
2019-07-09 12:47:39 +03:00
BigInt& operator-- ();
BigInt& operator++ ();
2019-07-07 21:10:53 +03:00
2019-07-11 13:05:25 +03:00
BigInt operator-- (int);
BigInt operator++ (int);
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator~ (BigInt val);
2019-07-07 21:10:53 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator| (BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator| (const BigInt &left, intMpz right);
2019-07-08 17:41:19 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator|= (BigInt &left, const BigInt& right);
friend BigInt& MINIGMPSHARED_EXPORT operator|= (BigInt &left, intMpz right);
2019-07-07 21:10:53 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator& (BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator& (const BigInt &left, intMpz right);
2019-07-09 12:47:39 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator&= (BigInt &left, const BigInt& right);
friend BigInt& MINIGMPSHARED_EXPORT operator&= (BigInt &left, intMpz right);
2019-07-09 12:47:39 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt MINIGMPSHARED_EXPORT operator^ (BigInt left, const BigInt& right);
friend BigInt MINIGMPSHARED_EXPORT operator^ (const BigInt &left, intMpz right);
2019-07-09 12:47:39 +03:00
2020-01-08 09:19:09 +03:00
friend BigInt& MINIGMPSHARED_EXPORT operator^= (BigInt &left, const BigInt& right);
friend BigInt& MINIGMPSHARED_EXPORT operator^= (BigInt &left, intMpz right);
2019-07-07 21:10:53 +03:00
2019-07-07 18:28:48 +03:00
};
#endif // BIGINT_H