📄 bigint.h
字号:
#ifndef CLASS_BIGINT
#define CLASS_BIGINT
#define TOTALBITS 64//大数采用的进制
#define TOTALBOXS 66//大数存储数组的位数
#define FULL 0xFFFFFFFFFFFFFFFF//大数每位的最大值,在大数的移位和减法中有很好的应用
#define ZERO 0x0
#define LenMAXHEX 16//16进制长度
#define LenMAXWRD 8//字节长度
typedef unsigned __int64 unsigned_int64;
typedef unsigned char byte;
//大数类
class BigInt
{
public:
BigInt();
virtual~BigInt();
unsigned __int64 iVal[TOTALBOXS];//存储大数的数组,采用"unsigned_int64'进制'"
unsigned short iIdx;//数组的位置
public:
void setZero();//置0
void setUpperBlock(const short &which);//找出比当前大数大的第一个2的幂
void loadHEX(const byte* itext,int size_num=0);//将itext以16进制形式装入大数
void loadSTR(const byte* itext,int size_num=0);//将itext以byte形式装入大数
byte* outputHEX();//将大数以16进制形式装入byte
byte* outputSTR();//将大数以String形式装入byte
//一系列的运算符重载,即大数运算库
BigInt& operator<<=(const short &iBit);
BigInt& operator>>=(const short &iBit);
BigInt& operator=(BigInt &p1);
BigInt& operator=(const unsigned_int64 &p1);
friend BigInt operator+(BigInt &p1,BigInt &p2);
friend BigInt operator+(BigInt &p1,const unsigned_int64 &p2);
friend BigInt operator-(BigInt &p1,BigInt &p2);
friend BigInt operator*(BigInt &p1,BigInt &p2);
friend BigInt operator*(BigInt &p1,const unsigned_int64 &p2);
friend BigInt operator/(BigInt &p1,BigInt &p2);
friend BigInt operator%(BigInt &p1,BigInt &p2);
friend inline bool operator>(BigInt &p1,BigInt &p2);
friend inline bool operator==(BigInt &p1,BigInt &p2);
friend inline bool operator!=(BigInt &p1,BigInt &p2);
BigInt& operator ++();
BigInt& operator --();
unsigned char Get4BitBlock(const short &which);//得到大数第which位(第which个4位块)
unsigned char Get4BitBlockZero();//得到存储大数数组最高位的0的个数(每位占4位2进制)
};
//BigInt operator-(BigInt &p1,BigInt &p2);
unsigned char hdigit(unsigned char c);//将字符转换成16进制字符
bool BIisZero(BigInt &x );//判断大数是否为0
int BIcompare(BigInt &p1,BigInt &p2);//大数间的比较
int BIcompare(BigInt &p1,const unsigned_int64 &p2);
void BIswap(BigInt &p1,BigInt &p2);//大数交换
BigInt BIdivision(BigInt &p1,BigInt &p2,BigInt &pr);//除法,返回商,pr余数
BigInt BImodmul(BigInt &p1,BigInt &p2,BigInt &pp);//大数模乘
BigInt BIinverse(BigInt &p1,BigInt &p2);//求逆
//用于大数的乘法,即每位相乘
void BImul(const unsigned_int64 &p1,const unsigned_int64 &p2,unsigned_int64 &high, unsigned_int64 &low);
//在除法和模运算中的应用,主要是使2个大数相近
void MakeThemClose(BigInt &p1,BigInt &p2);
short FindZeroBit(const unsigned_int64 &p1);//返回存储大数数组最高位的0的个数
void MakeModBaseTable(BigInt &p1);//建立预运算表,在两个大数模乘中的应用
BigInt MontMult(BigInt &p1,BigInt &p2,BigInt &pp);//蒙哥马利乘法
BigInt MontExpo(BigInt &p1,BigInt &p2,BigInt &pp);//蒙哥马利模幂
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -