VFP data using the MD5 algorithm to encrypt Author: Unknown Posted by: unknown Hits: 315 articles entry: windshadow Source: http: //www.souha.net/ArticleShow.asp ArticleID = 463?
Our VFP data is too open, with Excel to open a DBF table, and the data inside will be unopened. If the data is more sensitive, you can get a bad thing. For example: My data enteredman's program login password is placed in a VFP table. After encryption, even if you open the DBF table with Excel, you can't see your password. See this code from a book information disk for your reference.
------------------------------------ ******* md5.prg *** ******* FUNCTION LShift (lvalue, iShiftBits) IF iShiftBits = 0 RETURN lvalueELSEIF iShiftBits = 31 IF BITAND (lvalue, 1) <> 0 RETURN 0x80000000ELSERETURN 0ENDIFENDIFENDIFIF BITAND (lvalue, m_l2Power (31 - iShiftBits)) <> 0 RETURN BITOR ((BITAND (lvalue, m_lOnBits (31 - (iShiftBits 1))) * m_l2Power (iShiftBits)), 0x80000000) ELSERETURN (BITAND (lvalue, m_lOnBits (31 - iShiftBits)) * m_l2Power (iShiftBits)) ENDIFENDFUNCFUNCTION rShift ( lvalue, iShiftBits) IF iShiftBits = 0 RETURN lvalueELSEIF iShiftBits = 31 IF BITAND (lvalue, 0x80000000) RETURN 1ELSERETURN 0ENDIFENDIFENDIFRShift2 = INT (BITAND (lvalue, 0x7FFFFFFE) / m_l2Power (iShiftBits)) IF BITAND (lvalue, 0x80000000) <> 0 RShift2 = BITOR (RShift2, INT (0x40000000 / m_l2Power (iShiftBits - 1))) ENDIFRETURN RShift2ENDFUNCFUNCTION RotateLeft (lvalue, iShiftBits) RETURN BITOR (LShift (lvalue, iShiftBits), rShift (lvalue, (32 - iShiftBits))) ENDFUNCFUNCTION AddUnsigned (lX, LY) LX8 = Bitand (lx, 0x80000000) LY8 = B Itand (LY, 0X80000000) LX4 = Bitand (LX, 0x40000000) LY4 = Bitand (Ly, 0x40000000) LRESULT = Bitand (LX, 0x3fffffff) Bitand (Ly, 0x3fffff) IF Bitand (LX4, LY4) <> 0 LRESULT = bitxor (Bitxor (LRESULT, 0X80000000), LX8, LY8) Elseif Bitor (LRESULT, 0X40000000) <> 0 LRESULT = Bitxor (Bitxor (LRESULT, 0XC0000000) <> 0 LRESULT = BITXOR (Bitxor (LRESULT, 0XC0000000), LX8) , LY8) ElselResult = Bitxor (Bitxor (LRESULT, 0X40000000), LX8), LY8) endifelselresult =
Bitxor (LRESULT, LX8), LY8) endifendifreturn LresultendFuncfunction MD5_F (X, Y, Z) Return Bitor (BitNot (x, y)) endfuncfunction MD5_G (x, y, z) Return Bitor (Bitand (X, Z), Bitand (Y, BitNot (Z))) Endfuncfunction MD5_H (X, Y, Z) Return Bitxor (Bitxor (X, Y), Z) endfuncfunction MD5_i (x, y, z) Return Bitxor (Y, Bitor (x, bitNot (z))) EndfuncProcedure MD5_FF (A, B, C, D, X, S, AC) a = addunsigned (A, addunSigned (addunsigned (MD5_F (B, C, D) , X), AC)) A = Rotateleft (A, S) A = AddunSigned (A, B) EndProcprocedure MD5_GG (A, B, C, D, X, S, AC) a = addunsigned (A, AddUnsigned (AddunSigned MD5_G (B, C, D), X), AC)) A = Rotateleft (A, S) A = AddUnsigned (A, B) EndProcProcedure MD5_HH (A, B, C, D, X, S, AC) A = Addunsigned (A, AddunSigned (addunsigned (MD5_H (B, D), X), AC)) A = Rotateleft (A, S) a = addunsigned (A, b) endprocprocProcedure MD5_II (A, B, C, D, X, S, AC) a = addunsigned (A, addunsigned (addunsigned (MD5_I (B, C, D), X), AC)) a = rotateleft (a, s) a = addunsigned (A, b) endprocunction HEX lbyte) x = '' do wh Ile Lbyte> 0if lbyte> = 16Y = lbyte% 16ELSEY = LbyteEndifiF Y <10 .and. Y> = 0x = Str (Y, 1) Xelsex = CHR (65 Y-10) XenDiflbyte = (Lbyte-Y) / 16ENDDORETURN xENDFUNCFUNCTION WordToHex (lvalue) lResult = '' FOR lCount = 0 TO 3lByte = BITAND (rShift (lvalue, lCount * BITS_TO_A_BYTE), m_lOnBits (BITS_TO_A_BYTE)) lResult = lResult RIGHT (0 Hex (lByte), 2) ENDFORRETURN Lresultendfunc ************************************************************************************************************************************************************************************************************************************************************ *! * This is the main function of encryption, only one parameter SMESSAGE is a string *! * We say that MD5 is an irreversible encryption method, because it completely destroyed the structure of the original parameters *! * Below is the composition of the seed, the other party is not Decryption MD5 (SMESSAGE) BITS_TO_A_BYTE = 8BYTES_TO_A_WORD =
4BITS_TO_A_WORD = 32DIME m_lOnBits (31) DIME m_l2Power (31) m_lOnBits (1) = 1m_lOnBits (2) = 3m_lOnBits (3) = 7m_lOnBits (4) = 15m_lOnBits (5) = 31m_lOnBits (6) = 63m_lOnBits (7) = 127m_lOnBits (8 ) = 255m_lOnBits (9) = 511m_lOnBits (10) = 1023m_lOnBits (11) = 2047m_lOnBits (12) = 4095m_lOnBits (13) = 8191m_lOnBits (14) = 16383m_lOnBits (15) = 32767m_lOnBits (16) = 65535m_lOnBits (17) = 131071m_lOnBits (18 ) = 262143m_lOnBits (19) = 524287m_lOnBits (20) = 1048575m_lOnBits (21) = 2097151m_lOnBits (22) = 4194303m_lOnBits (23) = 8388607m_lOnBits (24) = 16777215m_lOnBits (25) = 33554431m_lOnBits (26) = 67108863m_lOnBits (27) = 134217727m_lOnBits (28 ) = 268435455m_lOnBits (29) = 536870911m_lOnBits (30) = 1073741823m_lOnBits (31) = 2147483647m_l2Power (1) = 1m_l2Power (2) = 2m_l2Power (3) = 4m_l2Power (4) = 8m_l2Power (5) = 16m_l2Power (6) = 32m_l2Power (7 ) = 64m_l2Power (8) = 128m_l2Power (9) = 256m_l2Power (10) = 512m_l2Power (11) = 1024m_l2Power (12) = 2048m_l2Power (13) = 4096m_l2Power (14) = 8192m_l2Power (15) = 16384m_l2Power (16) = 3276 8m_l2Power (17) = 65536m_l2Power (18) = 131072m_l2Power (19) = 262144m_l2Power (20) = 524288m_l2Power (21) = 1048576m_l2Power (22) = 2097152m_l2Power (23) = 4194304m_l2Power (24) = 8388608m_l2Power (25) = 16777216m_l2Power (26) = 33554432m_l2Power (27) = 67108864m_l2Power (28) = 134217728m_l2Power (29) = 268435456m_l2Power (30) = 536870912m_l2Power (31) = 1073741824S11 = 7S12 = 12S13 = 17S14 = 22S21 = 5S22 = 9S23 = 14S24 = 20S31 = 4S32 = 11S33 = 16S34 =
23S41 = 6S42 = 10S43 = 15S44 = 21 ********* Function ConvertToWordArray (sMessage) MODULUS_BITS = 512CONGRUENT_BITS = 448lMessageLength = LEN (sMessage) lNumberOfWords = (((lMessageLength INT (INT ((MODULUS_BITS - CONGRUENT_BITS) / BITS_TO_A_BYTE)) / INT (MODULUS_BITS / BITS_TO_A_BYTE))) 1) * INT (MODULUS_BITS / BITS_TO_A_WORD) DIME lWordArray (lNumberOfWords) STORE 0 TO lWordArraylBytePosition = 0lByteCount = 0DO WHILE lByteCount 4), S11, 0xF57c0FAFDO MD5_FF with D, A, B, C, X (K 5), S12, 0X4787C62ADO MD5_FF WITH C, D, A, B, X (K 6), S13, 0xA8304613DO MD5_FF with B, C, D, A, X (K 7), S14, 0xFD469501DO MD5_FF WITH A, B, C, D, X (K 8), S11, 0x698098D8DO MD5_FF with D, A, B, C, X (K 9), S12, 0x8B44F7AFDO MD5_FF WITH C, D, A, B, X (K 10), S13, 0xFFFF5BB1DO MD5_FF WITH B, C, D, A, X (K 11), S14, 0x895CD7BEDO MD5_FF with A, B, C, D, X (K 12), S11, 0x6B901122DO MD5_FF WITH D, A, B, C, X (K 13), S12, 0xFD987193DO MD5_FF WITH C, D, A, B, X (K 14), S13, 0xA679438EDO MD5_FF WITH B, C, D, A, X (K 15), S14, 0X49B40821DO MD5_GG WITH A, B, C, D, X (K 1), S21, 0xF61E2562DO MD5_GG WITH D, A, B, C, X (K 6), S22, 0XC040B340DO MD5_GG WITH C, D, A, B, X (K 11), S23, 0x265E5A51DO MD5_GG WITH B, C, D, A, X (k 0), S24, 0xE9B6C7AADO MD5_GG WITH A, B, C, D, X (K 5), S21, 0XD62F105DDO MD5_GG WITH D, A, B, C, X (K 10), S22, 0x2441453DO MD5_GG WITH C, D, A, B, X (K 15), S23, 0XD8A1E681DO MD5_GG WITH B, C, D, A, X (k 4), S24, 0xE7D3FBC8DO MD5_GG WITH A, B, C, D, X (K 9), S21, 0x21E1CDE6DO MD5_GG WITH D, A, B, C, X (K 14), S22, 0XC33707D6DO MD5_GG WITH C, D, A , B, X (K 3), S23, 0xF4D50D87DO MD5_GG WITH B, C, D, A, X (K 8), S24, 0x455A14EDDO MD5_GG WITH A, B, C, D, X (K 13), S21, 0xA9E3E905DO MD5_GG WITH D, A, B, C, X (K 2), S22, 0XFCEFA3F8DO MD5_GG WITH C, D, A, B, X (K 7), S23, 0x676F02D9DO MD5_GG WITH B, C, D , A, X (k 12), S24, 0x8D2A4C8ADO MD5_HH WITH A, B, C, D, X (K 5), S31, 0xFFFA3942DO MD5_HH with D, A, B, C, X (k 8), S32, 0x8771F681DO MD5_HH WITH C, D, A, B, X (K 11), S33, 0x6D9D6122DO MD5_HH with B, C, D, A, X (k 14), S34, 0xFDE5380CDO MD5_HH WITH A, B, C, D, X (K 1), S31, 0XA4Beea44DO MD5_HH with D, A, B, C, X (K 4), S32, 0x4BDECFA9DO MD5_HH with C, D, A, B, X (K 7), S33, 0XF6BB4B60DO MD5_HH WITH B, C, D, A, X (K 10), S34, 0XBEBFBC70DO MD5_HH WITH A, B, C, D, X (K 13), S31, 0x289B7EC6DO MD5_HH with D, A, B, C, X (K 0), S32, 0xEAA127FADO MD5_HH with C, D, A, B, X (K 3), S33, 0xD4ef3085DO MD5_HH with B, C, D, A, X (K 6), S34, 0X4881D05DO MD5_HH WITH A, B, C, D, X (K 9), S31, 0xD9D4D039DO MD5_HH with D, A, B, C, X (k 12), S32, 0xE6DB99E5DO MD5_HH WITH C, D, A, B, X (K 15), S33, 0x1FA27CF8DO MD5_HH WITH B, C, D, A, X (K 2), S34, 0xC4AC5665DO MD5_II with A, B, C, D, X (K 0), S41, 0xF429244DO MD5_II with D, A, B, C, X (K 7), S42, 0x432AFF97DO MD5_II with C, D, A, B, X (k 14), S43, 0XAB9423A7DO MD5_II With B, C, D, A, X (K 5), S44, 0xFC93A039DO MD5_II WITH A, B, C, D, X (K 12), S41, 0x655B59C3DO MD5_II with D, A, B, C, X (K 3), S42, 0x8F0CCC92DO MD5_II With C, D, A, B, X (K 10), S 43, 0xffeff47ddo MD5_II with B, C, D, A, X (k 1), S44, 0x85845DD1DO MD5_II WITH A, B, C, D, X (K 8), S41, 0x6FA87E4FDO MD5_II with D, A, B , C, X (K 15), S42, 0XFE2CE6E0DO MD5_II With C, D, A, B, X (K 6), S43, 0XA3014314DO MD5_II With B, C, D, A, X (K 13), S44, 0X4E0811A1DO MD5_II With A, B, C, D, X (K 4), S41, 0xF7537E82DO MD5_II with D, A, B, C, X (K 11), S42, 0xBD3AF235DO MD5_II with C, D, A , B, X (K 2), S43, 0X2AD7D2BDO MD5_II With B, C, D, A, X (K 9), S44, 0XEB86D391A = Addunsigned (A, AA) B = AddunSigned (B, BB) c = Addunsigned (C, CC) D = AddunSigned (D, DD) Endforon Error &&