Implementation of C #, VB of MD5 encryption algorithm (16, 32)

xiaoxiao2021-04-10  597

The following is the implementation of the MD5 algorithm with C #

//Md5.cs

// MD5 16-bit, 32-bits algorithm mailmented in c #

Using system;

Using system.text;

Namespace Encrypter

{

///

/// Summary Description for MD5.

///

Public Class MD5

{

Const int bits_to_a_byte = 8;

const Int Bytes_to_A_WORD = 4;

Const int bits_to_a_word = 32;

Private static long [] M_LONBITS = New long [30 1];

Private static long [] m_l2power = new long [30 1];

Private Static Long Lshift (Long Lvalue, Long iShiftBITS)

{

Long lshift = 0;

IF (iShiftBits == 0)

{

Lshift = LVALUE;

Return lshift;

}

Else

{

IF (iShiftBits == 31)

{

IF (Convert.TOBOOLEAN (Lvalue & 1))

{

Lshift = 0x80000000;

}

Else

{

Lshift = 0;

}

Return lshift;

}

Else

{

IF (IshiftBits <0 || ishiftbits> 31)

{

// Err.raise 6;

}

}

}

IF (Convert.TOBOOLEAN ((Lvalue & M_L2Power [31 - IshiftBits])))))))

{

LSHIFT = ((Lvalue & M_Lonbits [31 - (iShiftBits 1)]) * m_l2power [iShiftBits] | 0x80000000;

}

Else

{

LSHIFT = ((Lvalue & M_lonbits [31 - IshiftBits]) * m_l2power [iShiftBits]);

}

Return lshift;

}

Private Static Long Rshift (Long Lvalue, Long iShiftBits)

{

Long rshift = 0;

IF (iShiftBits == 0)

{

Rshift = LVALUE;

Return Rshift;

}

Else

{

IF (iShiftBits == 31)

{

IF (Convert.TOBOOLEAN (LValue & 0x80000000))

{

Rshift = 1;

}

Else

{

Rshift = 0;

}

Return Rshift;

}

Else

{

IF (IshiftBits <0 || ishiftbits> 31)

{

// Err.raise 6;

}

}

}

Rshift = (Lvalue & 0x7ffffe) / m_l2power [iShiftBits];

IF (Convert.TOBOOLEAN ((Lvalue & 0x80000000))))

{

Rshift = (Rshift | (0x40000000 / m_l2power [iShiftBits - 1])));

}

Return Rshift;

}

Private Static Long RotateLeft (Long Lvalue, Long iShiftBits)

{

Long RotateLeft = 0;

RotateLeft = Lshift (Lvalue, IshiftBits) | RSHIFT (Lvalue, (32 - iShiftBits);

Return RotateLeft;

}

Private Static Long Addunsigned (Long LX, Long LY)

{

Long addunsigned = 0;

Long LX4 = 0;

LONG LY4 = 0;

Long lx8 = 0;

LONG LY8 = 0;

Long LRESULT = 0;

LX8 = lx & 0x80000000;

LY8 = LY & 0x80000000;

LX4 = lx & 0x40000000;

LY4 = LY & 0x40000000;

LRESULT = (LX & 0x3ffffffff) (LY & 0x3FFFFFF);

IF (Convert.TOBOOLEAN (LX4 & LY4))

{

LRESULT = LRESULT ^ 0x80000000 ^ LX8 ^ LY8;

}

Else IF (Convert.TOBOOLAN (LX4 | LY4))

{

IF (Convert.TOBOOLEAN (LRESULT & 0X40000000))

{

LRESULT = LRESULT ^ 0xc0000000 ^ LX8 ^ LY8;

}

Else

{

LRESULT = LRESULT ^ 0x40000000 ^ LX8 ^ LY8;

}

}

Else

{

LRESULT = LRESULT ^ LX8 ^ LY8;

}

Addunsigned = LRESULT;

Return addunsigned;

}

Private Static Long MD5_F (long x, long y, long z)

{

Long MD5_F = 0;

MD5_f = (x & y) | ((~ x) & z);

RETURN MD5_F;

}

PRIVATE STATIC long MD5_G (long x, long y, long z)

{

Long MD5_G = 0;

MD5_G = (X & Z) | (Y & (~ Z));

RETURN MD5_G;

}

Private Static Long MD5_H (long x, long y, long z)

{

Long MD5_H = 0;

MD5_H = (x ^ y ^ z);

RETURN MD5_H;

}

Private Static Long MD5_I (Long X, Long Y, Long Z)

{

Long MD5_I = 0;

MD5_i = (y ^ (x | (~ z)));

Return MD5_i;

}

Private Static Void MD5_FF (Ref Long A, Long B, Long C, Long D, Long X, Long S, long AC)

{

A = AddunSigned (A, AddunSigned (AddunSigned (MD5_F (B, C, D), X), AC);

A = RotateLeft (A, S);

A = addunsigned (A, b);

}

PRIVATE Static Void MD5_GG (Ref Long A, Long B, LONG C, LONG D, Long X, Long S, Long AC) {

A = AddunSigned (A, AddunSigned (AddunSigned (MD5_G (B, C, D), X), AC);

A = RotateLeft (A, S);

A = addunsigned (A, b);

}

PRIVATE STATIC VOID MD5_HH (Ref Long A, Long B, Long C, Long D, Long X, Long S, long AC)

{

A = AddunSigned (A, AddunSigned (AddunSigned (MD5_H (B, C, D), X), AC);

A = RotateLeft (A, S);

A = addunsigned (A, b);

}

Private Static Void MD5_II (Ref Long A, Long B, LONG C, LONG D, Long X, Long S, Long AC)

{

A = addunsigned (A, AddunSigned (AddunSigned (MD5_I (B, C, D), X), AC);

A = RotateLeft (A, S);

A = addunsigned (A, b);

}

Private static long [] ConvertToWordArray (String SMESSAGE)

{

Long [] ConvertToWordArray = NULL;

INT LMESSAGELENGTH = 0;

INT lnumberofwords = 0;

Long [] lwordArray = null;

INT lbyteposition = 0;

INT LBYTECOUNT = 0;

INT LWORDCOUNT = 0;

Const int modulus_bits = 512;

Const int congruent_bits = 448;

LimentageLength = SMESSAGE.LENGTH;

LNUMBEROFWORDS = ((LMessageLength (MODULUS_BITS - CONGRUENT_BITS / BITS_TO_A_BYTE)) / (MODULUS_BITS / BITS_TO_A_BYTE)) 1) * (MODULUS_BITS / BITS_TO_A_WORD);

LWORDARRAY = New long [lnumberofwords];

lbyteposition = 0;

Lbytecount = 0;

While (lbytecount

{

LWORDCOUNT = lbytecount / bytes_to_a_word;

LbytePosition = (lbytecount% BYTES_TO_A_WORD) * bits_to_a_byte;

LWordArray [LWORDCOUNT] = lwordArray [LWORDCOUNT] | LSHIFT (SMESSAGE.SUBSTRING (Lbytecount, 1) .tochararray () [0]), LbyTeposition);

Lbytecount = lbytecount 1;

}

LWORDCOUNT = lbytecount / bytes_to_a_word;

LbytePosition = (lbytecount% BYTES_TO_A_WORD) * bits_to_a_byte; lwordArray [lwordcount] = lwordArray [lwordcount] | lshift (0x80, lbyteposition);

LWordArray [lnumberofwords - 2] = lshift (LMESSAGALELENGTH, 3);

LWordArray [lnumberofwords - 1] = RSHIFT (LMESSAGALELENGTH, 29);

ConvertToWordArray = lwordArray;

Return ConvertToWordArray;

}

Private Static String Wordtohex (Long Lvalue)

{

String Wordtohex = ""

Long lbyte = 0;

INT LCOUNT = 0;

For (lcount = 0; lcount <= 3; lcount )

{

Lbyte = RSHIFT (LVALUE, LCOUNT * BITS_TO_A_BYTE) & M_LONBITS [BITS_TO_A_BYTE - 1];

Wordtohex = WordToHex (("0" tohex (lbyte)). Substring (("0" tohex (lbyte)). Length - 2));

}

Return WordTohex;

}

Private static string tohex (long dec)

{

String strhex = "";

While (dec> 0)

{

Strhex = tohex (dec% 16) strhex;

Dec = DEC / 16;

}

Return strhex;

}

Private static string tohex (long hex)

{

String strhex = "";

Switch (HEX)

{

CASE 10: strhex = "a"; Break;

Case 11: strhex = "b"; Break;

CASE 12: strhex = "c"; Break;

CASE 13: strhex = "d"; breaf;

CASE 14: strhex = "e"; Break;

CASE 15: strhex = "f"; Break;

Default: strhex = hex.tostring (); Break;

}

Return strhex;

}

Public Static String Encrypt (String SMESSAGE, INTSEPE)

{

String MD5 = "";

For (INT i = 0; i <= 30; i )

{

M_lonbits [i] = convert.toint64 (Math.Pow (2, i 1) -1);

M_L2POWER [I] = Convert.Toint64 (Math.Pow (2, i));

}

Long [] x = NULL;

INT K = 0;

Long aa = 0;

Long bb = 0;

Long cc = 0;

Long DD = 0;

Long a = 0; long b = 0;

Long c = 0;

Long D = 0;

Const Int S11 = 7;

Const Int S12 = 12;

Const Int S13 = 17;

Const Int S14 = 22;

Const Int S21 = 5;

Const Int S22 = 9;

Const Int S23 = 14;

Const Int S24 = 20;

Const Int S31 = 4;

Const Int S32 = 11;

Const Int S33 = 16;

Const Int S34 = 23;

Const Int S41 = 6;

Const Int S42 = 10;

Const Int S43 = 15;

Const Int S44 = 21;

X = ConvertToWordArray (SMESSAGE);

A = 0x67452301;

B = 0xefcdab89;

C = 0x98badcfe;

D = 0x10325476;

For (k = 0; k

{

AA = a;

BB = B;

CC = C;

DD = D;

MD5_FF (REF A, B, C, D, X [K 0], S11, 0xD76AA478);

MD5_FF (REF D, A, B, C, X [K 1], S12, 0xE8C7B756);

MD5_FF (REF C, D, A, B, X [K 2], S13, 0x242070dB);

MD5_FF (REF B, C, D, A, X [K 3], S14, 0XC1BDCEEE);

MD5_FF (REF A, B, C, D, X [K 4], S11, 0xF57c0FAF);

MD5_FF (REF D, A, B, C, X [K 5], S12, 0x4787C62A);

MD5_FF (REF C, D, A, B, X [K 6], S13, 0xA8304613);

MD5_FF (REF B, C, D, A, X [K 7], S14, 0xFD469501);

MD5_FF (REF A, B, C, D, X [K 8], S11, 0x698098D8);

MD5_FF (REF D, A, B, C, X [K 9], S12, 0x8B44F7AF);

MD5_FF (REF C, D, A, B, X [K 10], S13, 0xFFFF5BB1);

MD5_FF (REF B, C, D, A, X [K 11], S14, 0x895CD7BE);

MD5_FF (REF A, B, C, D, X [K 12], S11, 0x6b901122);

MD5_FF (REF D, A, B, C, X [K 13], S12, 0xFD987193);

MD5_FF (REF C, D, A, B, X [K 14], S13, 0xA679438E);

MD5_FF (REF B, C, D, A, X [K 15], S14, 0X49B40821);

MD5_GG (REF A, B, C, D, X [K 1], S21, 0xF61E2562);

MD5_GG (REF D, A, B, C, X [K 6], S22, 0XC040B340);

MD5_GG (REF C, D, A, B, X [K 11], S23, 0x265E5A51); MD5_GG (Ref B, C, D, A, X [K 0], S24, 0xE9B6C7AA);

MD5_GG (REF A, B, C, D, X [K 5], S21, 0xD62F105D);

MD5_GG (REF D, A, B, C, X [K 10], S22, 0x2441453);

MD5_GG (REF C, D, A, B, X [K 15], S23, 0xD8A1E681);

MD5_GG (REF B, C, D, A, X [K 4], S24, 0xE7D3FBC8);

MD5_GG (REF A, B, C, D, X [K 9], S21, 0x21E1CDE6);

MD5_GG (REF D, A, B, C, X [K 14], S22, 0XC33707D6);

MD5_GG (REF C, D, A, B, X [K 3], S23, 0xF4D50D87);

MD5_GG (REF B, C, D, A, X [K 8], S24, 0x455A14ED);

MD5_GG (REF A, B, C, D, X [K 13], S21, 0XA9E3E905);

MD5_GG (REF D, A, B, C, X [K 2], S22, 0xFCEFA3F8);

MD5_GG (REF C, D, A, B, X [K 7], S23, 0x676F02D9);

MD5_GG (REF B, C, D, A, X [K 12], S24, 0x8D2A4C8A);

MD5_HH (REF A, B, C, D, X [K 5], S31, 0xFFFA3942);

MD5_HH (REF D, A, B, C, X [K 8], S32, 0x8771F681);

MD5_HH (REF C, D, A, B, X [K 11], S33, 0x6D9D6122);

MD5_HH (REF B, C, D, A, X [K 14], S34, 0xFDE5380C);

MD5_HH (REF A, B, C, D, X [K 1], S31, 0xA4Beea44);

MD5_HH (REF D, A, B, C, X [K 4], S32, 0x4BDECFA9);

MD5_HH (REF C, D, A, B, X [K 7], S33, 0xF6BB4B60);

MD5_HH (REF B, C, D, A, X [K 10], S34, 0XBEBFBC70);

MD5_HH (REF A, B, C, D, X [K 13], S31, 0x289B7EC6);

MD5_HH (REF D, A, B, C, X [K 0], S32, 0xEAA127FA);

MD5_HH (REF C, D, A, B, X [K 3], S33, 0xD4ef3085);

MD5_HH (REF B, C, D, A, X [K 6], S34, 0x4881D05);

MD5_HH (REF A, B, C, D, X [K 9], S31, 0xD9D4D039);

MD5_HH (REF D, A, B, C, X [K 12], S32, 0xE6DB99E5);

MD5_HH (REF C, D, A, B, X [K 15], S33, 0x1FA27CF8);

MD5_HH (REF B, C, D, A, X [K 2], S34, 0xC4AC5665);

MD5_II (REF A, B, C, D, X [K 0], S41, 0XF4292244);

MD5_II (REF D, A, B, C, X [K 7], S42, 0x432AFF97); MD5_II (REF C, D, A, B, X [K 14], S43, 0XAB9423A7);

MD5_II (REF B, C, D, A, X [K 5], S44, 0xFC93A039);

MD5_II (REF A, B, C, D, X [K 12], S41, 0X655B59C3);

MD5_II (REF D, A, B, C, X [K 3], S42, 0x8F0CCC92);

MD5_II (REF C, D, A, B, X [K 10], S43, 0xffeff47d);

MD5_II (REF B, C, D, A, X [K 1], S44, 0x85845DD1);

MD5_II (REF A, B, C, D, X [K 8], S41, 0X6FA87E4F);

MD5_II (REF D, A, B, C, X [K 15], S42, 0XFE2CE6E0);

MD5_II (REF C, D, A, B, X [K 6], S43, 0XA3014314);

MD5_II (REF B, C, D, A, X [K 13], S44, 0X4E0811A1);

MD5_II (REF A, B, C, D, X [K 4], S41, 0xF7537E82);

MD5_II (REF D, A, B, C, X [K 11], S42, 0XBD3AF235);

MD5_II (REF C, D, A, B, X [K 2], S43, 0x2AD7D2BB);

MD5_II (REF B, C, D, A, X [K 9], S44, 0XEB86D391);

A = AddunSigned (A, AA);

B = addunsigned (b, bb);

C = AddunSigned (C, CC);

D = AddunSigned (D, DD);

}

IF (Stype == 32)

{

MD5 = (((WordToHex (a)) (WordTohex (c))) (WordTohex (D))). TOLOWER ();

}

Else

{

MD5 = ((WordTohex (B)) (WordTohex (C))). TOLOWER ();

}

Return MD5;

}

}

}

The following is the implementation of the MD5 algorithm for VB

//Md5.vb

// MD5 16-bit, 32-bits algorithm implemented in vb

Namespace Encrypter

Public Class MD5

PRIVATE CONST BITS_TO_A_BYTE AS INTEGER = 8

PRIVATE const BYTES_TO_A_WORD AS INTEGER = 4

PRIVATE CONST BITS_TO_A_WORD AS INTEGER = 32

Private shared m_lonbits (30) as long

Private shared m_l2power (30) as long

Public Shared Function Lshift (Byval Lvalue As Long) AS Long

IF iShiftBits = 0 THEN

Lshift = LVALUE

EXIT FUNCTION

Elseif ishiftBits = 31 THEN

IF Lvalue and 1 THEN

Lshift = & h80000000lse

Lshift = 0

END IF

EXIT FUNCTION

Elseif IshiftBits <0 or iShiftBits> 31 THEN

Err.raise (6)

END IF

IF (LValue and M_L2Power (31 - IshiftBits)) THEN

Lshift = ((Lvalue and M_lonbits (31 - (iShiftBits 1))) * m_l2power (iShiftBits)) or & h80000000

Else

Lshift = ((Lvalue and M_Lonbits) * m_l2power (iShiftBits))

END IF

END FUNCTION

Public Shared Function Rshift (Byval Lvalue As Long, BYVAL ISHIFTBITS AS INTEGER) AS Long

IF iShiftBits = 0 THEN

Rshift = LVALUE

EXIT FUNCTION

Elseif ishiftBits = 31 THEN

If Lvalue and & H80000000 THEN

Rshift = 1

Else

Rshift = 0

END IF

EXIT FUNCTION

Elseif IshiftBits <0 or iShiftBits> 31 THEN

Err.raise (6)

END IF

Rshift = (LValue and & H7ffffe) / M_L2Power (iShiftBits)

IF (Lvalue and & H80000000) THEN

Rshift = (RSHIFT OR (& H400000 / M_L2Power (IshiftBits - 1)))

END IF

END FUNCTION

Public Shared Function RotateLeft (BYVAL LVALUE AS Long, Byval IshiftBits as "

Rotateleft = Lshift (Lvalue, IshiftBits) or Rshift (Lvalue, (32 - IshiftBits))

END FUNCTION

Private Shared Function Add (Byval Lx As Long, Byval Ly As Long) As Long

DIM LX4 AS Long

DIM LY4 AS Long

DIM LX8 AS Long

DIM LY8 AS Long

DIM LRESULT AS Long

Lx8 = lx and & h80000000

LY8 = ly and & h80000000

LX4 = lx and & h40000000

LY4 = Ly and & H40000000

LRESULT = (lx and & h3ffffff) (Ly and & H3FFFFFF)

IF lx4 and ly4 Then

Lresult = LRESULT XOR & H80000000 XOR LX8 XOR LY8

Elseif Lx4 or Ly4 Then

If LRESULT AND & H40000000 THEN

LResult = LRESULT XOR & HC0000000 XOR LX8 XOR LY8

Else

Lresult = LRESULT XOR & H40000000 XOR LX8 XOR LY8END IF

Else

LResult = LRESULT XOR LX8 XOR LY8

END IF

Addunsigned = LRESULT

END FUNCTION

Private Shared Function MD5_F (Byval X As Long, Byval Y As Long) AS Long

MD5_F = (x and y) OR ((not x) and z)

END FUNCTION

Private Shared Function MD5_G (BYVAL X As Long, Byval Y As Long, BYVAL Z As Long) As long

MD5_G = (x and z) OR (Y AND (NOT Z))

END FUNCTION

Private Shared Function MD5_H (Byval X As Long, Byval Y As Long) AS Long

MD5_H = (x xor y xor z)

END FUNCTION

Private Shared Function MD5_i (BYVAL X As Long, Byval Y As Long, BYVAL Z As Long) AS Long

MD5_i = (y xor (x or (not z))))

END FUNCTION

Private Shared Sub MD5_FF (byref A As Long, Byval C As Long, Byval D As Long, BYVAL X As Long, Byval S as Long, ByVal AC As Long)

A = AddunSigned (A, AddunSigned (addunsigned (MD5_F (B, C, D), X), AC)

a = rotateleft (a, s)

A = addunsigned (a, b)

End Sub

Private Shared Sub MD5_GG (byref A As Long, Byval C As Long, Byval D As Long, BYVAL X As Long, Byval S As Long, BYVAL AC As Long)

A = addunsigned (A, AddunSigned (addunsigned (MD5_G (B, C, D), X), AC)

a = rotateleft (a, s)

A = addunsigned (a, b)

End Sub

Private Shared Sub MD5_HH (byref A As Long, Byval C As Long, Byval D As Long, BYVAL X as Long, Byval S as Long, ByVal AC As Long)

A = addunsigned (A, AddunSigned (addunsigned (MD5_H (B, C, D), X), AC)

a = rotateleft (a, s)

A = addunsigned (a, b)

End Sub

Private Shared Sub MD5_II (byref A As Long, Byval C As Long, Byval D As Long, BYVAL X As Long, Byval S As Long, Byval AC As Long)

A = addunsigned (A, AddunSigned (AddunSigned (MD5_i (B, D), X), AC)) A = RotateLeft (A, S)

A = addunsigned (a, b)

End Sub

Private Shared Function ConvertToWordArray (Byval SMESSAGE AS STRING)

Dim LMessageLength As Integer

Dim lnumberofwords as integer

Dim lwordArray () As long

DIM LBYTEPSITION AS INTEGER

Dim lbytecount as integer

DIM LWORDCOUNT AS INTEGER

Const modulus_bits as long = 512

Const congruent_bits as long = 448

LMessageLength = Len (SMESSAGE)

Lnumberofwords = ((LMessageLength ((MODULUS_BITS - CONGRUENT_BITS / BITS_TO_A_BYTE)) / (MODULUS_BITS / BITS_TO_A_BYTE)) 1) * (MODULUS_BITS / BITS_TO_A_WORD)

Redim LWordArray (LnumberofWords - 1)

lbyteposition = 0

lbytecount = 0

DO Until Lbytecount> = LMESSAGELENGTH

LWORDCOUNT = lbytecount / bytes_to_a_word

LbytePosition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte

LWordArray (LWORDCOUNT) OR LSHIFT (ASC (MID (SMESSAGE, LBYTECUNT 1, 1)), LBYTEPOSITION

lbytecount = lbytecount 1

Loop

LWORDCOUNT = lbytecount / bytes_to_a_word

LbytePosition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte

LWordArray (lwordcount) = lwordArray (lwordcount) or lshift (& H80, lbyteposition)

LWordArray (lnumberofwords - 2) = lshift (LMessageLength, 3)

LWordArray (Lnumberofwords - 1) = RSHIFT (LMessageLength, 29)

ConvertToWordArray = LWORDARRAY

END FUNCTION

Public Shared Function Wordtohex (Byval Lvalue As Long)

Dim lbyte as long

DIM LCOUNT AS Long

For LCOUNT = 0 TO 3

Lbyte = RSHIFT (LVALUE, LCOUNT * BITS_TO_A_BYTE) AND M_LONBITS (Bits_TO_A_BYTE - 1)

Wordtohex = WordToHex & Right ("0" & ​​HEX (LbyTe), 2)

NEXT

End functionpublic shared function encrypt (Byval SMESSAGE AS STRING, BYVAL STYPE AS INTEGER)

m_lonbits (0) = ClNG (1)

M_lonbits (1) = CLNG (3)

M_lonbits (2) = CLNG (7)

M_lonbits (3) = CLNG (15)

M_lonbits (4) = CLNG (31)

M_lonbits (5) = clng (63)

M_lonbit (6) = CLNG (127)

M_lonbits (7) = CLNG (255)

M_lonbits (8) = CLNG (511)

m_lonbits (9) = CLNG (1023)

M_lonbits (10) = CLNG (2047)

M_lonbits (11) = clng (4095)

M_lonbits (12) = CLNG (8191)

m_lonbits (13) = CLNG (16383)

M_lonbits (14) = CLNG (32767)

M_lonbits (15) = CLNG (65535)

M_lonbits (16) = CLNG (131071)

M_lonbits (17) = CLNG (262143)

M_lonbits (18) = CLNG (524287)

M_lonbits (19) = clng (1048575)

M_lonbits (20) = CLNG (2097151)

M_lonbits (21) = clng (4194303)

M_lonbits (22) = CLNG (8388607)

M_lonbits (23) = CLNG (16777215)

M_LONBITS (24) = CLNG (33554431)

M_LONBITS (25) = CLNG (67108863)

M_lonbits (26) = CLNG (134217727)

M_lonbit (27) = CLNG (268435455)

M_lonbit (28) = CLNG (536870911)

M_lonbits (29) = CLNG (1073741823)

M_lonbits (30) = clng (2147483647)

m_l2power (0) = CLNG (1)

M_L2Power (1) = CLNG (2)

M_L2Power (2) = CLNG (4)

M_L2Power (3) = CLNG (8)

M_L2Power (4) = CLNG (16)

M_L2Power (5) = CLNG (32)

M_L2Power (6) = CLNG (64)

M_L2Power (7) = clng (128)

M_L2Power (8) = CLNG (256)

M_L2Power (9) = CLNG (512)

M_L2Power (10) = CLNG (1024)

M_L2Power (11) = CLNG (2048)

M_L2Power (12) = CLNG (4096)

M_L2Power (13) = clng (8192)

M_L2Power (14) = CLNG (16384)

M_L2Power (15) = CLNG (32768)

M_L2Power (16) = CLNG (65536)

m_l2power (17) = CLNG (131072)

M_L2Power (18) = CLNG (262144)

M_L2Power (19) = CLNG (524288)

M_L2POWER (20) = CLNG (1048576) M_L2Power (21) = CLNG (2097152)

M_L2Power (22) = CLNG (4194304)

M_L2Power (23) = CLNG (8388608)

M_L2Power (24) = CLNG (16777216)

M_L2Power (25) = CLNG (33554432)

M_L2Power (26) = CLNG (67108864)

M_L2Power (27) = CLNG (134217728)

M_L2Power (28) = CLNG (268435456)

M_L2Power (29) = CLNG (536870912)

M_L2Power (30) = CLNG (1073741824)

DIM x () as long

DIM K As Integer

DIM AA AS INTEGER

DIM BB AS INTEGER

DIM CC AS INTEGER

DIM DD AS INTEGER

Dim a as integer

DIM B AS INTEGER

DIM C AS Integer

DIM D AS INTEGER

Const S11 as integer = 7

Const S12 AS Integer = 12

Const S13 as integer = 17

Const S14 AS Integer = 22

Const S21 AS Integer = 5

Const S22 as INTEGER = 9

Const S23 AS Integer = 14

Const S24 AS Integer = 20

Const S31 As INTEGER = 4

Const S32 as INTEGER = 11

Const S33 as INTEGER = 16

Const S34 AS Integer = 23

Const S41 as INTEGER = 6

Const S42 as INTEGER = 10

Const S43 AS Integer = 15

Const S44 as INTEGER = 21

x = ConvertToWordArray (SMESSAGE)

A = & h67452301

B = & hefcdab89

C = & H98BADCFE

D = & h10325476

For K = 0 to Ubound (x) STEP 16

AA = a

BB = B

CC = C

DD = D

MD5_FF (A, B, C, D, X (K 0), S11, & HD76AA478)

MD5_FF (D, A, B, C, X (K 1), S12, & HE8C7B756)

MD5_FF (C, D, A, B, X (K 2), S13, & H242070DB)

MD5_FF (B, C, D, A, X (K 3), S14, & HC1BDCEEE)

MD5_FF (A, B, C, D, X (K 4), S11, & HF57C0FAF)

MD5_FF (D, A, B, C, X (K 5), S12, & H4787C62A)

MD5_FF (C, D, A, B, X (K 6), S13, & HA8304613)

MD5_FF (B, C, D, A, X (K 7), S14, & HFD469501)

MD5_FF (A, B, C, D, X (K 8), S11, & H698098D8) MD5_FF (D, A, B, C, X (K 9), S12, & H8B44F7AF)

MD5_FF (C, D, A, B, X (k 10), S13, & HFFFF5BB1)

MD5_FF (B, C, D, A, X (K 11), S14, & H895CD7BE)

MD5_FF (A, B, C, D, X (K 12), S11, & H6B901122)

MD5_FF (D, A, B, C, X (K 13), S12, & HFD987193)

MD5_FF (C, D, A, B, X (K 14), S13, & Ha679438E)

MD5_FF (B, C, D, A, X (K 15), S14, & H49B40821)

MD5_GG (A, B, C, D, X (K 1), S21, & HF61E2562)

MD5_GG (D, A, B, C, X (K 6), S22, & HC040B340)

MD5_GG (C, D, A, B, X (K 11), S23, & H265E5A51)

MD5_GG (B, C, D, A, X (K 0), S24, & HE9B6C7AA)

MD5_GG (A, B, C, D, X (K 5), S21, & HD62F105D)

MD5_GG (D, A, B, C, X (K 10), S22, & H2441453)

MD5_GG (C, D, A, B, X (K 15), S23, & HD8A1E681)

MD5_GG (B, C, D, A, X (K 4), S24, & HE7D3FBC8)

MD5_GG (A, B, C, D, X (K 9), S21, & H21E1CDE6)

MD5_GG (D, A, B, C, X (K 14), S22, & HC33707D6)

MD5_GG (C, D, A, B, X (K 3), S23, & HF4D50D87)

MD5_GG (B, C, D, A, X (K 8), S24, & H455A14ED)

MD5_GG (A, B, C, D, X (K 13), S21, & HA9E3E905)

MD5_GG (D, A, B, C, X (K 2), S22, & HFCEFA3F8)

MD5_GG (C, D, A, B, X (K 7), S23, & H676F02D9)

MD5_GG (B, C, D, A, X (K 12), S24, & H8D2A4C8A)

MD5_HH (A, B, C, D, X (K 5), S31, & HFFFA3942)

MD5_HH (D, A, B, C, X (K 8), S32, & H8771F681)

MD5_HH (C, D, A, B, X (K 11), S33, & H6D9D6122)

MD5_HH (B, C, D, A, X (K 14), S34, & HFDE5380C)

MD5_HH (A, B, C, D, X (K 1), S31, & Ha4bee44)

MD5_HH (D, A, B, C, X (K 4), S32, & H4BDECFA9)

MD5_HH (C, D, A, B, X (K 7), S33, & HF6BB4B60)

MD5_HH (B, C, D, A, X (K 10), S34, & HBebfbc70) MD5_HH (A, B, C, D, X (K 13), S31, & H289B7EC6)

MD5_HH (D, A, B, C, X (K 0), S32, & HEAA127FA)

MD5_HH (C, D, A, B, X (K 3), S33, & HD4EF3085)

MD5_HH (B, C, D, A, X (K 6), S34, & H4881D05)

MD5_HH (A, B, C, D, X (K 9), S31, & HD9D4D039)

MD5_HH (D, A, B, C, X (K 12), S32, & HE6DB99E5)

MD5_HH (C, D, A, B, X (K 15), S33, & H1FA27CF8)

MD5_HH (B, C, D, A, X (K 2), S34, & HC4AC5665)

MD5_II (A, B, C, D, X (K 0), S41, & HF4292244)

MD5_II (D, A, B, C, X (K 7), S42, & H432AFF97)

MD5_II (C, D, A, B, X (K 14), S43, & HAB9423A7)

MD5_II (B, C, D, A, X (K 5), S44, & HFC93A039)

MD5_II (A, B, C, D, X (K 12), S41, & H655B59C3)

MD5_II (D, A, B, C, X (K 3), S42, & H8F0CCC92)

MD5_II (C, D, A, B, X (K 10), S43, & HFFEFF47D)

MD5_II (B, C, D, A, X (K 1), S44, & H85845DD1)

MD5_II (A, B, C, D, X (K 8), S41, & H6FA87E4F)

MD5_II (D, A, B, C, X (K 15), S42, & HFE2CE6E0)

MD5_II (C, D, A, B, X (K 6), S43, & HA3014314)

MD5_II (B, C, D, A, X (K 13), S44, & H4E0811A1)

MD5_II (A, B, C, D, X (K 4), S41, & HF7537E82)

MD5_II (D, A, B, C, X (K 11), S42, & HBD3AF235)

MD5_II (C, D, A, B, X (K 2), S43, & H2AD7D2BB)

MD5_II (B, C, D, A, X (K 9), S44, & HEB86D391)

Console.writeline (a)

A = addunsigned (A, AA)

B = addunsigned (b, bb)

C = addunsigned (C, CC)

D = addunsigned (D, DD)

NEXT

IF stype = 32 THEN

Encrypt = lcase (WordTohex (a) & WordTohex (B) & WordTohex (C) & WordToHex (D))

Else

Encrypt = lcase (WordTohex (B) & WordToHex (C))

END IF

END FUNCTION

END CLASS

End Namespace

转载请注明原文地址:https://www.9cbs.com/read-133351.html

New Post(0)