bigint.h

来自「RSA公钥密钥生成程序,C++语言编写,采用了自己的大数类,可在短时间内生成10」· C头文件 代码 · 共 61 行

H
61
字号
#include <iostream>
using namespace std;

const int size=64;

class BigInt{

friend BigInt operator+ (const BigInt&, const BigInt&);
friend BigInt operator- (const BigInt&, const BigInt&);
friend BigInt operator- (const BigInt&, const int&);
friend BigInt operator* (const BigInt&, const BigInt&);
friend BigInt operator% (const BigInt&, const BigInt&);
friend BigInt operator/ (const BigInt&, const BigInt&);
friend BigInt operator* (const BigInt&, const unsigned int&);
friend bool operator< (const BigInt&, const BigInt&);
friend bool operator> (const BigInt&, const BigInt&);
friend bool operator<= (const BigInt&, const int&);
friend bool operator== (const BigInt&, const BigInt&);
friend bool operator== (const BigInt&, const int&);
friend ostream& operator<< (ostream&, const BigInt&);
friend BigInt PowerMode (const BigInt&,const BigInt&, const BigInt&);
friend SortPrime(BigInt& n);

public:
	BigInt();
	BigInt(const int&);
	BigInt(const BigInt&);

	operator= (const BigInt&);
	operator= (const int& a) { Clear(); data[0]=a;}
	operator>> (const int&);

    inline int GetLength() const;    //返回大数的长度
	bool TestSign() {return sign;}   //判断大数的正负 
	Clear();    //大数清0
	Random();   //随机产生一个大数
    Randomsmall();  //随机产生一个稍小的大数
	display() const;  
	Output(ostream& out) const;
	bool IsOdd() const {return (data[0]&1);}    //判断大数奇偶性

private:
	unsigned int data[size];
	bool sign;
};

BigInt operator+ (const BigInt&, const BigInt&);
BigInt operator- (const BigInt&, const BigInt&);
BigInt operator- (const BigInt&, const int&);
BigInt operator* (const BigInt&, const BigInt&);
BigInt operator/ (const BigInt&, const BigInt&);
BigInt operator% (const BigInt&, const BigInt&);
BigInt operator* (const BigInt&, const unsigned int&);
BigInt PowerMode (const BigInt&,const BigInt&, const BigInt&);
bool operator< (const BigInt&, const BigInt&);
bool operator> (const BigInt&, const BigInt&);
bool operator<= (const BigInt&, const int&);
bool operator== (const BigInt&, const BigInt&);
bool operator== (const BigInt&, const int&);
ostream& operator<< (ostream&, const BigInt&);
SortPrime(BigInt& n);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?