(To test the email of the code to WWB206@163.com)
I don't busy a few days ago, so I remembered the encryption algorithm, but RSA encryption was relying on a large number of operations, and the mainstream RSA algorithm was established at 512 bits to 1024. The most existing computer data type is 64 (INT64), so I have composed a large number of CXWORD to implement 1024-bit large numbers. Basic thinking is to store the array of DWORD [32], which is implemented as follows. (To speed up the running speed, all functions are inline) / ****************************************** ****************************** / file: // WORD number of long header file: CXWord.hfile: // author: wwb206 @ 163.comfile: // Version: 1.0 (2004.2.17) File: // Description: Will the large number as an N-based array, for the current 32-bit system, N can take the file: // value 2 32 times, 0x00000000 <> 0xfffffffff / *********************************************** ************************* / file: // # if defined WWB_XWORD2004021711025632100 # ifndef WWB_XWORD2004021711025632100 # define WWB_XWORD2004021711025632100file:! // # define WWB_XWORDDEBUGfile: // The number of groups, indicating that the maximum number of representations is 2 ^ (32 * 32) = 2 ^ 1024, that is, 1024 digits const DWORD XWORDLEN = 32; class cxword {private: DWORD DATA [xwordlen]; // Reserved [] other public: inline int getlen () const; inline CXWord LOffset (int value); inline CXWord operator (const CXWord value) const; inline CXWord operator (const DWORD value) const; inline CXWord operator- (const CXWord value) const Inline Cxword Operator- (const DWord value) const; inline cxword settor * (const dword value) const; inline cxword operator / (const cxword value) Con st; inline CXWord operator / (const DWORD value) const; inline CXWord operator% (const CXWord value) const; inline DWORD operator% (const DWORD value) const; inline CXWord operator = (const CXWord value); inline CXWord operator = ( Const dword value); inline cxword operator << (const dword bitcount); inline cxword operator >> (Const DWORD BITCOUNT);
inline bool operator> (const DWORD value) const; inline bool operator> (const CXWord value) const; inline bool operator <(const DWORD value) const; inline bool operator <(const CXWord value) const; inline bool operator> = ( const DWORD value) const; inline bool operator> = (const CXWord value) const; inline bool operator <= (const DWORD value) const; inline bool operator <= (const CXWord value) const; inline bool operator == (const CXWord value) const; inline bool operator == (const DWORD value) const; inline CXWord sqrt () const; inline CString Format16 () const; inline CString Format10 () const; inline void operator (); inline void operator - () Inline cxword (); inline cxword (cstring value); inline ~ cxword () {;}}; file: // dword chartonum (char C);
Inline DWord Chartonum (CAAR C) {Case '0': Case '1': Case '2': Case '3': Case '4': Case '5': Case '6': Case ' 7 ': Case' 8 ': Case' 9 ': Return 0 C-'0'; Case 'A': Case 'B': Case 'C': Case 'D': Case 'E': Case 'f ': Return 10 c-'a';} cstring str1 = C; MessageBox (0, "incorrect characters", str1, mb_ok | mb_iconstop); return 0;} cxword :: cxword () {for (DWORD D) = 0; D Value.makeupper (); if (value.left (2) == "0x") {value.delete (0, 2); for (DWORD D = 0; D * this = * this TMP;}}} cstring cxword :: format16 () const {cstring str1, str2; int dlen = this-> getlen (); for (int D = 0; D CString cxword :: format10 () const {cstring str1, str2; cxword residue, quotient, dividend = (* this), TMP = (* this); // 数, commercial, divisor, temporary I = 0; while (DivideD) > = 10) {i ; quotient = divident / 10; residue = dividend - quotient * 10; // <10 str1.format ("% 01d", Residue.Data [0]); if (i% 10 == 0 ) str1 = "," str1; str2 = str1 str2; dividend = quotient;} str1.format ("% 01d", dividend; str2 = str1 str2; return str2;} Inline Bool Cxword :: Operator == (const cxword value) const {for (DWORD D = 0; D While (true) {result = (maxResult minResult) / 2; if (Result * Result> (* this)) {maxResult = result;} else if (Result * Result <= (* this)) {x x = result 1; IF (XTMP * XTMP <= * this) {minResult = Result;} else break; // Return Result;} Return Result;}; inline cxword cxword :: Operator / (const cxword value) const {cxword result, maxresult, minResult; if ((* this) Int rlen = this-> getlen () - value.getlen (); file: // for (DWord D = 0; D } Return Result;} inline cxword cxword :: operator% (const cxword value) const {cxword result, tmp; tmp = (* this) / value; result = ((* this) - tmp * value); Return Result;} Inline cxword cxword :: Operator / (const dword value) const {// xyzk / w /// Int Datalen; for (DATALEN = xwordlen; datalen> 0; datalenten ---) IF (Data [DataLen-1]! = 0) Break; unsigned __INT64 DIVIDEND; // Demodes DWORD Residue, quotient; //, remainder, business, divisor DWORD DQWS = DATALEN-1; // Current Bits CXWORD XQUOTIENT, XTEMP = * this; While (TRUE) {if (xtemp.data [dqws] Xtemp.Data [DQWS] = 0; xTemp.data [DQWS-1] = Residue; xquotient.data [DQWS-1] = quotient; dqws--;}} else // xtemp.data [dqws]> = value { DividEnd = xtemp.data [dqws]; residue = divident% value; quotient = Dividend / value; XQUOTIENT.DATA [DQWS] = quotient xquotient.data [dqws]; xtemp.data [dqws] = Residue;}} Return xquotient; Inline dword cxword :: operator% (const dword value) const {cxword w1; w1 = * this / value; w1 = * this - (w1 * value); return w1.data [0]; } // a b // b C d // Inline cxword cxword :: Operator (const cxword value) const {cxword result; unsigned __INT64 x, carry = 0; // carry flag for (DWORD D = 0; D x = (unsigned __INT64) Value this-> Data [0]; carry = x >> 32; Result.Data [0] = (x << 32) >> 32; for (DWORD D = 1; D Inline Bool CXWORD :: Operator> Const {for (DWORD D = 1; D TMP = Value * Data [D]; // for (DWORD D2 = 0; D2 Tmp.Data [xWordlen-1-D2] = tmp.data [xwordlen-1-d-d2];} for (DWORD D3 = 0; D3 Result = result TMP; }}} Inline cxword cxword :: operator * (const dword value) const {cxword result; unsigned __INT64 x, carry = 0; // carry flag for (DWORD D = 0; D }}}}}} Inline cxword cxword :: Operator- (const dword value) const {cxword result; if (* this #ENDIF