📄 uvlong.h
字号:
// uvlong.h: interface for the uvlong class.
//
//////////////////////////////////////////////////////////////////////
#include <Windows.h>
#include <memory.h>
#include <time.h>
#include <stdlib.h>
//////////////////////////////////////////////////////////////////////////////
#define RSA_ERR_OK 00 //正常
#define RSA_ERR_OF 01 //溢出错误
#define RSA_ERR_02 02 //参数错误
//////////////////////////////////////////////////////////////////////////////
/*CLINTMAXDIGIT表示ULINT对象的最大位数(以unsigned short为单位)*/
#define CLINTMAXDIGIT 250
typedef unsigned short ushort;
typedef ushort ULINT[CLINTMAXDIGIT+1];
/*取得ULINT对象x的大小*/
#define GET_CLINTSIZE(x) ( x[0] )
/*设置ULINT对象x的大小*/
#define SET_CLINTSIZE(x,l) ( x[0] = l)
/*取得ULINT对象x某一位的值*/
#define GET_CLINT(x,i) ( x[i] )
//--------------------------------------------------------------------------
#define BPU ( 8*sizeof(unsigned short) ) // Number of bits in an unsigned short
#define lo(x) ( (x) & ((1<<(BPU/2))-1) ) // lower half of unsigned short
#define hi(x) ( (x) >> (BPU/2) ) // upper half
#define lh(x) ( (x) << (BPU/2) ) // make upper half
//----------------------------------------------------------------------
class uvlong
{
public:
/*两个ULINT对象相加*/
friend int add_cl(ULINT const a,ULINT const b,ULINT s);
/*两个ULINT对象相减*/
friend int sub_cl(ULINT const a,ULINT const b,ULINT s);
/*复制一个对象到另一个对象*/
friend int copy_cl(ULINT a, ULINT const b);
/*比较两个ULINT对象大小*/
friend int comp_cl( ULINT const a,ULINT const b);
/*两个ULINT对象相乘*/
friend int mul_cl( ULINT const a, ULINT const b, ULINT mul, int keep = 0);
/*两个ULINT对象相除*/
friend int div_cl( ULINT const a, ULINT const b, ULINT div , ULINT rem);
/*大数乘方("平方"-和-乘法)*/
/* "Euclid" method to receive the mod inverse
Assume: m>a, Get: u*a+v*b = (a,b) */
friend int modexp_cl( const ULINT x, const ULINT e,const ULINT mod,ULINT result);
/*求最大公因子*/
friend int gcd_cl( const ULINT X, const ULINT Y ,ULINT result);
/*清除多余位*/
friend int trim( ULINT a);
/*判断是否为0*/
friend int IsZero(const ULINT a);
/*清空ULINT对象*/
friend void clean_cl(ULINT x);
/*左移一个bit,*2 */
friend void shl_cl(ULINT x);
/*右移一个bit,/2 */
friend void shr_cl(ULINT x);
/*初始化一个对象*/
friend void init_cl(ULINT x,ushort v=0);
//-------------------------------------------------------------------------------
uvlong& modexp( const uvlong & m, const uvlong & e, const uvlong & mod );
uvlong& gcd( const uvlong & a, const uvlong & b);
uvlong& Append( const ushort& x );
uvlong ( );
uvlong (unsigned int x );
virtual ~uvlong();
operator unsigned ();
int GetBits() const;
void ReArray();
int test( unsigned int i ) const;
ULINT m_clint;
int m_share; // share count, used by vlong to delay physical copying
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -