现在很多加密是用MD5的,谁知道有可算法吗?(100分)

  • 主题发起人 主题发起人 huotangdelphi
  • 开始时间 开始时间
H

huotangdelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
MD5算法如下(VB程序,谁有DELPHI程序,贴上来):
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32
Private m_lOnBits(30)
Private m_l2Power(30)

Private Function LShift(lValue, iShiftBits)
If iShiftBits = 0 then
LShift = lValue
Exit Function
else
If iShiftBits = 31 then
If lValue And 1 then
LShift = &H80000000
else
LShift = 0
End If
Exit Function
else
If 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 &amp;H80000000
else
LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
End If
End Function
Private Function RShift(lValue, iShiftBits)
If iShiftBits = 0 then
RShift = lValue
Exit Function
else
If iShiftBits = 31 then
If lValue And &amp;H80000000 then
RShift = 1
else
RShift = 0
End If
Exit Function
else
If iShiftBits < 0 Or iShiftBits > 31 then
Err.Raise 6
End If

RShift = (lValue And &amp;H7FFFFFFE) / m_l2Power(iShiftBits)
If (lValue And &amp;H80000000) then
RShift = (RShift Or (&amp;H40000000 / m_l2Power(iShiftBits - 1)))
End If
End Function
Private Function RotateLeft(lValue, iShiftBits)
RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
End Function
Private Function AddUnsigned(lX, lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult

lX8 = lX And &amp;H80000000
lY8 = lY And &amp;H80000000
lX4 = lX And &amp;H40000000
lY4 = lY And &amp;H40000000

lResult = (lX And &amp;H3FFFFFFF) + (lY And &amp;H3FFFFFFF)

If lX4 And lY4 then
lResult = lResult Xor &amp;H80000000 Xor lX8 Xor lY8
else
If lX4 Or lY4 then
If lResult And &amp;H40000000 then
lResult = lResult Xor &amp;HC0000000 Xor lX8 Xor lY8
else
lResult = lResult Xor &amp;H40000000 Xor lX8 Xor lY8
End If
else
lResult = lResult Xor lX8 Xor lY8
End If

AddUnsigned = lResult
End Function
Private Function md5_F(x, y, z)
md5_F = (x And y) Or ((Not x) And z)
End Function
Private Function md5_G(x, y, z)
md5_G = (x And z) Or (y And (Not z))
End Function
Private Function md5_H(x, y, z)
md5_H = (x Xor y Xor z)
End Function
Private Function md5_I(x, y, z)
md5_I = (y Xor (x Or (Not z)))
End Function
Private Sub 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)
End Sub
Private Sub 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)
End Sub
Private Sub md5_HH(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_H(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub
Private Sub 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)
End Sub
Private Function ConvertToWordArray(sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount

Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 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) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 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(&amp;H80, lBytePosition)
lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)

ConvertToWordArray = lWordArray
End Function
Private Function WordToHex(lValue)
Dim lByte
Dim lCount

For lCount = 0 To 3
lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
WordToHex = WordToHex &amp;
Right("0" &amp;
Hex(lByte), 2)
Next
End Function
Public Function MD5(sMessage)
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_lOnBits(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_lOnBits(27) = CLng(268435455)
m_lOnBits(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
Dim k
Dim AA
Dim BB
Dim CC
Dim DD
Dim a
Dim b
Dim c
Dim d

Const S11 = 7
Const S12 = 12
Const S13 = 17
Const S14 = 22
Const S21 = 5
Const S22 = 9
Const S23 = 14
Const S24 = 20
Const S31 = 4
Const S32 = 11
Const S33 = 16
Const S34 = 23
Const S41 = 6
Const S42 = 10
Const S43 = 15
Const S44 = 21
x = ConvertToWordArray(sMessage)

a = &amp;H67452301
b = &amp;HEFCDAB89
c = &amp;H98BADCFE
d = &amp;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, &amp;HD76AA478
md5_FF d, a, b, c, x(k + 1), S12, &amp;HE8C7B756
md5_FF c, d, a, b, x(k + 2), S13, &amp;H242070DB
md5_FF b, c, d, a, x(k + 3), S14, &amp;HC1BDCEEE
md5_FF a, b, c, d, x(k + 4), S11, &amp;HF57C0FAF
md5_FF d, a, b, c, x(k + 5), S12, &amp;H4787C62A
md5_FF c, d, a, b, x(k + 6), S13, &amp;HA8304613
md5_FF b, c, d, a, x(k + 7), S14, &amp;HFD469501
md5_FF a, b, c, d, x(k + 8), S11, &amp;H698098D8
md5_FF d, a, b, c, x(k + 9), S12, &amp;H8B44F7AF
md5_FF c, d, a, b, x(k + 10), S13, &amp;HFFFF5BB1
md5_FF b, c, d, a, x(k + 11), S14, &amp;H895CD7BE
md5_FF a, b, c, d, x(k + 12), S11, &amp;H6B901122
md5_FF d, a, b, c, x(k + 13), S12, &amp;HFD987193
md5_FF c, d, a, b, x(k + 14), S13, &amp;HA679438E
md5_FF b, c, d, a, x(k + 15), S14, &amp;H49B40821

md5_GG a, b, c, d, x(k + 1), S21, &amp;HF61E2562
md5_GG d, a, b, c, x(k + 6), S22, &amp;HC040B340
md5_GG c, d, a, b, x(k + 11), S23, &amp;H265E5A51
md5_GG b, c, d, a, x(k + 0), S24, &amp;HE9B6C7AA
md5_GG a, b, c, d, x(k + 5), S21, &amp;HD62F105D
md5_GG d, a, b, c, x(k + 10), S22, &amp;H2441453
md5_GG c, d, a, b, x(k + 15), S23, &amp;HD8A1E681
md5_GG b, c, d, a, x(k + 4), S24, &amp;HE7D3FBC8
md5_GG a, b, c, d, x(k + 9), S21, &amp;H21E1CDE6
md5_GG d, a, b, c, x(k + 14), S22, &amp;HC33707D6
md5_GG c, d, a, b, x(k + 3), S23, &amp;HF4D50D87
md5_GG b, c, d, a, x(k + 8), S24, &amp;H455A14ED
md5_GG a, b, c, d, x(k + 13), S21, &amp;HA9E3E905
md5_GG d, a, b, c, x(k + 2), S22, &amp;HFCEFA3F8
md5_GG c, d, a, b, x(k + 7), S23, &amp;H676F02D9
md5_GG b, c, d, a, x(k + 12), S24, &amp;H8D2A4C8A

md5_HH a, b, c, d, x(k + 5), S31, &amp;HFFFA3942
md5_HH d, a, b, c, x(k + 8), S32, &amp;H8771F681
md5_HH c, d, a, b, x(k + 11), S33, &amp;H6D9D6122
md5_HH b, c, d, a, x(k + 14), S34, &amp;HFDE5380C
md5_HH a, b, c, d, x(k + 1), S31, &amp;HA4BEEA44
md5_HH d, a, b, c, x(k + 4), S32, &amp;H4BDECFA9
md5_HH c, d, a, b, x(k + 7), S33, &amp;HF6BB4B60
md5_HH b, c, d, a, x(k + 10), S34, &amp;HBEBFBC70
md5_HH a, b, c, d, x(k + 13), S31, &amp;H289B7EC6
md5_HH d, a, b, c, x(k + 0), S32, &amp;HEAA127FA
md5_HH c, d, a, b, x(k + 3), S33, &amp;HD4EF3085
md5_HH b, c, d, a, x(k + 6), S34, &amp;H4881D05
md5_HH a, b, c, d, x(k + 9), S31, &amp;HD9D4D039
md5_HH d, a, b, c, x(k + 12), S32, &amp;HE6DB99E5
md5_HH c, d, a, b, x(k + 15), S33, &amp;H1FA27CF8
md5_HH b, c, d, a, x(k + 2), S34, &amp;HC4AC5665

md5_II a, b, c, d, x(k + 0), S41, &amp;HF4292244
md5_II d, a, b, c, x(k + 7), S42, &amp;H432AFF97
md5_II c, d, a, b, x(k + 14), S43, &amp;HAB9423A7
md5_II b, c, d, a, x(k + 5), S44, &amp;HFC93A039
md5_II a, b, c, d, x(k + 12), S41, &amp;H655B59C3
md5_II d, a, b, c, x(k + 3), S42, &amp;H8F0CCC92
md5_II c, d, a, b, x(k + 10), S43, &amp;HFFEFF47D
md5_II b, c, d, a, x(k + 1), S44, &amp;H85845DD1
md5_II a, b, c, d, x(k + 8), S41, &amp;H6FA87E4F
md5_II d, a, b, c, x(k + 15), S42, &amp;HFE2CE6E0
md5_II c, d, a, b, x(k + 6), S43, &amp;HA3014314
md5_II b, c, d, a, x(k + 13), S44, &amp;H4E0811A1
md5_II a, b, c, d, x(k + 4), S41, &amp;HF7537E82
md5_II d, a, b, c, x(k + 11), S42, &amp;HBD3AF235
md5_II c, d, a, b, x(k + 2), S43, &amp;H2AD7D2BB
md5_II b, c, d, a, x(k + 9), S44, &amp;HEB86D391

a = AddUnsigned(a, AA)
b = AddUnsigned(b, BB)
c = AddUnsigned(c, CC)
d = AddUnsigned(d, DD)
Next

'MD5 = LCase(WordToHex(a) &amp;
WordToHex(b) &amp;
WordToHex(c) &amp;
WordToHex(d))
MD5=LCase(WordToHex(b) &amp;
WordToHex(c)) 'I crop this to fit 16byte database password :D
End Function
 
{*******************************}
{ }
{ MD5? }
{ author: 19'98 Yankovsky }
{ Date: 6.1.2002 }
{ }
{*******************************}
{-------------------------------------------------------------------------------
UNIT: MD5Unit
Sample:
procedure TForm1.Button1Click(Sender: TObject);
var
MD5Hash: TMD5;
OutputArray: array[0..15] of Char;
begin
MD5Hash := TMD5.Create;
try
MD5Hash.InputType := itString;
MD5Hash.InputString := Edit1.Text;
MD5Hash.POutputArray := @OutputArray;
MD5Hash.HashCalc;
Edit1.Text := OutputArray;
finally
MD5Hash.Free;
end;
end;
-------------------------------------------------------------------------------}
unit MD5Unit;
interface
uses SysUtils;
type
PLong = ^Longword;
TInputType = (itString, itFile, itByteArray);
PHashDigest = ^THashDigest;
THashDigest = record
A,
B,
C,
D: Longword;
end;

TMD5 = class
private
FInputType: TInputType;
FInputString: string;
FInputFilePath: string;
FPInputArray: PByteArray;
FInputLength: Longword;
FOutputDigest: PHashDigest;
FActiveBlock: array[0..15] of Longword;
FA, FB, FC, FD, FAA, FBB, FCC, FDD: Longword;
FpA, FpB, FpC, FpD: PLong;
procedure FF(a, b, c, d, x: Pointer;
s: Byte;
ac: Longword);
procedure GG(a, b, c, d, x: Pointer;
s: Byte;
ac: Longword);
procedure HH(a, b, c, d, x: Pointer;
s: Byte;
ac: Longword);
procedure II(a, b, c, d, x: Pointer;
s: Byte;
ac: Longword);
public
procedure HashInit;
procedure HashTransform;
procedure HashFinish;
procedure HashBytes;
procedure HashFile;
procedure HashCalc;
property InputType: TInputType read FInputType write FInputType;
property InputString: string read FInputString write FInputString;
property InputFilePath: string read FInputFilePath write FInputFilePath;
property PInputArray: PByteArray read FPInputArray write FPInputArray;
property InputLength: Longword read FInputLength write FInputLength;
property POutputArray: PHashDigest read FOutputDigest write FOutputDigest;
end;

const
S11 = 7;
S12 = 12;
S13 = 17;
S14 = 22;
S21 = 5;
S22 = 9;
S23 = 14;
S24 = 20;
S31 = 4;
S32 = 11;
S33 = 16;
S34 = 23;
S41 = 6;
S42 = 10;
S43 = 15;
S44 = 21;
implementation
function ROL(val: Longword;
shift: Byte): LongWord;
assembler;
asm
MOV EAX, val;
MOV CL, shift;
ROL EAX, CL;
end;

procedure TMD5.HashInit;
var
a, b, c, d: Longword;
begin
a := $67452301;
b := $efcdab89;
c := $98badcfe;
d := $10325476;
Move(a, FA, 4);
FpA := @FA;
Move(b, FB, 4);
FpB := @FB;
Move(c, FC, 4);
FpC := @FC;
Move(d, FD, 4);
FpD := @FD;
end;

{Purpose: Round 1 of the Transform.
Equivalent to a = b + ((a + F(b,c,d) + x + ac) <<< s)
Where F(b,c,d) = b And c Or Not(b) And d}
procedure TMD5.FF(a, b, c, d, x: Pointer;
s: Byte;
ac: Longword);
var
Fret: Longword;
begin
Fret := ((PLong(b)^) and (PLong(c)^)) or ((not(PLong(b)^)) and (PLong(d)^));
PLong(a)^ := PLong(a)^ + Fret + PLong(x)^ + ac;
Longword(a^) := ROL(Longword(a^), s);
Inc(PLong(a)^, PLong(b)^);
end;

{Purpose: Round 2 of the Transform.
Equivalent to a = b + ((a + G(b,c,d) + x + ac) <<< s)
Where G(b,c,d) = b And d Or c Not d}
procedure TMD5.GG(a, b, c, d, x: Pointer;
s: Byte;
ac: Longword);
var
Gret: Longword;
begin
Gret := (PLong(b)^ and PLong(d)^) or ( PLong(c)^ and (not PLong(d)^));
PLong(a)^ := PLong(a)^ + Gret + PLong(x)^ + ac;
Longword(a^) := ROL(Longword(a^), s);
Inc(PLong(a)^, PLong(b)^);
end;

{Purpose: Round 3 of the Transform.
Equivalent to a = b + ((a + H(b,c,d) + x + ac) <<< s)
Where H(b,c,d) = b Xor c Xor d}
procedure TMD5.HH(a, b, c, d, x: Pointer;
s: Byte;
ac: Longword);
var
Hret: Longword;
begin
Hret := PLong(b)^ xor PLong(c)^ xor PLong(d)^;
PLong(a)^ := PLong(a)^ + Hret + PLong(x)^ + ac;
Longword(a^) := ROL(Longword(a^), s);
PLong(a)^ := PLong(b)^ + PLong(a)^;
end;

{Purpose: Round 4 of the Transform.
Equivalent to a = b + ((a + I(b,c,d) + x + ac) <<< s)
Where I(b,c,d) = C Xor (b Or Not(d))}
procedure TMD5.II(a, b, c, d, x: Pointer;
s: Byte;
ac: Longword);
var
Iret: Longword;
begin
Iret := (PLong(c)^ xor (PLong(b)^ or (not PLong(d)^)));
PLong(a)^ := PLong(a)^ + Iret + PLong(x)^ + ac;
Longword(a^) := ROL(PLong(a)^, s );
PLong(a)^ := PLong(b)^ + PLong(a)^;
end;

{Purpose: Perform Step 4 of the algorithm. This is where all the important
stuff happens. This performs the rounds on a 64Byte Block. This
procedure should be called in a loop until all input data has been
transformed.}
procedure TMD5.HashTransform;
begin
FAA := FA;
FBB := FB;
FCC := FC;
FDD := FD;
{ Round 1 }
FF(FpA, FpB, FpC, FpD, @FActiveBlock[ 0], S11, $d76aa478);
{ 1 }
FF(FpD, FpA, FpB, FpC, @FActiveBlock[ 1], S12, $e8c7b756);
{ 2 }
FF(FpC, FpD, FpA, FpB, @FActiveBlock[ 2], S13, $242070db);
{ 3 }
FF(FpB, FpC, FpD, FpA, @FActiveBlock[ 3], S14, $c1bdceee);
{ 4 }
FF(FpA, FpB, FpC, FpD, @FActiveBlock[ 4], S11, $f57c0faf);
{ 5 }
FF(FpD, FpA, FpB, FpC, @FActiveBlock[ 5], S12, $4787c62a);
{ 6 }
FF(FpC, FpD, FpA, FpB, @FActiveBlock[ 6], S13, $a8304613);
{ 7 }
FF(FpB, FpC, FpD, FpA, @FActiveBlock[ 7], S14, $fd469501);
{ 8 }
FF(FpA, FpB, FpC, FpD, @FActiveBlock[ 8], S11, $698098d8);
{ 9 }
FF(FpD, FpA, FpB, FpC, @FActiveBlock[ 9], S12, $8b44f7af);
{ 10 }
FF(FpC, FpD, FpA, FpB, @FActiveBlock[10], S13, $ffff5bb1);
{ 11 }
FF(FpB, FpC, FpD, FpA, @FActiveBlock[11], S14, $895cd7be);
{ 12 }
FF(FpA, FpB, FpC, FpD, @FActiveBlock[12], S11, $6b901122);
{ 13 }
FF(FpD, FpA, FpB, FpC, @FActiveBlock[13], S12, $fd987193);
{ 14 }
FF(FpC, FpD, FpA, FpB, @FActiveBlock[14], S13, $a679438e);
{ 15 }
FF(FpB, FpC, FpD, FpA, @FActiveBlock[15], S14, $49b40821);
{ 16 }
{ Round 2 }
GG(FpA, FpB, FpC, FpD, @FActiveBlock[ 1], S21, $f61e2562);
{ 17 }
GG(FpD, FpA, FpB, FpC, @FActiveBlock[ 6], S22, $c040b340);
{ 18 }
GG(FpC, FpD, FpA, FpB, @FActiveBlock[11], S23, $265e5a51);
{ 19 }
GG(FpB, FpC, FpD, FpA, @FActiveBlock[ 0], S24, $e9b6c7aa);
{ 20 }
GG(FpA, FpB, FpC, FpD, @FActiveBlock[ 5], S21, $d62f105d);
{ 21 }
GG(FpD, FpA, FpB, FpC, @FActiveBlock[10], S22, $02441453);
{ 22 }
GG(FpC, FpD, FpA, FpB, @FActiveBlock[15], S23, $d8a1e681);
{ 23 }
GG(FpB, FpC, FpD, FpA, @FActiveBlock[ 4], S24, $e7d3fbc8);
{ 24 }
GG(FpA, FpB, FpC, FpD, @FActiveBlock[ 9], S21, $21e1cde6);
{ 25 }
GG(FpD, FpA, FpB, FpC, @FActiveBlock[14], S22, $c33707d6);
{ 26 }
GG(FpC, FpD, FpA, FpB, @FActiveBlock[ 3], S23, $f4d50d87);
{ 27 }
GG(FpB, FpC, FpD, FpA, @FActiveBlock[ 8], S24, $455a14ed);
{ 28 }
GG(FpA, FpB, FpC, FpD, @FActiveBlock[13], S21, $a9e3e905);
{ 29 }
GG(FpD, FpA, FpB, FpC, @FActiveBlock[ 2], S22, $fcefa3f8);
{ 30 }
GG(FpC, FpD, FpA, FpB, @FActiveBlock[ 7], S23, $676f02d9);
{ 31 }
GG(FpB, FpC, FpD, FpA, @FActiveBlock[12], S24, $8d2a4c8a);
{ 32 }
{ Round 3 }
HH(FpA, FpB, FpC, FpD, @FActiveBlock[ 5], S31, $fffa3942);
{ 33 }
HH(FpD, FpA, FpB, FpC, @FActiveBlock[ 8], S32, $8771f681);
{ 34 }
HH(FpC, FpD, FpA, FpB, @FActiveBlock[11], S33, $6d9d6122);
{ 35 }
HH(FpB, FpC, FpD, FpA, @FActiveBlock[14], S34, $fde5380c);
{ 36 }
HH(FpA, FpB, FpC, FpD, @FActiveBlock[ 1], S31, $a4beea44);
{ 37 }
HH(FpD, FpA, FpB, FpC, @FActiveBlock[ 4], S32, $4bdecfa9);
{ 38 }
HH(FpC, FpD, FpA, FpB, @FActiveBlock[ 7], S33, $f6bb4b60);
{ 39 }
HH(FpB, FpC, FpD, FpA, @FActiveBlock[10], S34, $bebfbc70);
{ 40 }
HH(FpA, FpB, FpC, FpD, @FActiveBlock[13], S31, $289b7ec6);
{ 41 }
HH(FpD, FpA, FpB, FpC, @FActiveBlock[ 0], S32, $eaa127fa);
{ 42 }
HH(FpC, FpD, FpA, FpB, @FActiveBlock[ 3], S33, $d4ef3085);
{ 43 }
HH(FpB, FpC, FpD, FpA, @FActiveBlock[ 6], S34, $04881d05);
{ 44 }
HH(FpA, FpB, FpC, FpD, @FActiveBlock[ 9], S31, $d9d4d039);
{ 45 }
HH(FpD, FpA, FpB, FpC, @FActiveBlock[12], S32, $e6db99e5);
{ 46 }
HH(FpC, FpD, FpA, FpB, @FActiveBlock[15], S33, $1fa27cf8);
{ 47 }
HH(FpB, FpC, FpD, FpA, @FActiveBlock[ 2], S34, $c4ac5665);
{ 48 }
{ Round 4 }
II(FpA, FpB, FpC, FpD, @FActiveBlock[ 0], S41, $f4292244);
{ 49 }
II(FpD, FpA, FpB, FpC, @FActiveBlock[ 7], S42, $432aff97);
{ 50 }
II(FpC, FpD, FpA, FpB, @FActiveBlock[14], S43, $ab9423a7);
{ 51 }
II(FpB, FpC, FpD, FpA, @FActiveBlock[ 5], S44, $fc93a039);
{ 52 }
II(FpA, FpB, FpC, FpD, @FActiveBlock[12], S41, $655b59c3);
{ 53 }
II(FpD, FpA, FpB, FpC, @FActiveBlock[ 3], S42, $8f0ccc92);
{ 54 }
II(FpC, FpD, FpA, FpB, @FActiveBlock[10], S43, $ffeff47d);
{ 55 }
II(FpB, FpC, FpD, FpA, @FActiveBlock[ 1], S44, $85845dd1);
{ 56 }
II(FpA, FpB, FpC, FpD, @FActiveBlock[ 8], S41, $6fa87e4f);
{ 57 }
II(FpD, FpA, FpB, FpC, @FActiveBlock[15], S42, $fe2ce6e0);
{ 58 }
II(FpC, FpD, FpA, FpB, @FActiveBlock[ 6], S43, $a3014314);
{ 59 }
II(FpB, FpC, FpD, FpA, @FActiveBlock[13], S44, $4e0811a1);
{ 60 }
II(FpA, FpB, FpC, FpD, @FActiveBlock[ 4], S41, $f7537e82);
{ 61 }
II(FpD, FpA, FpB, FpC, @FActiveBlock[11], S42, $bd3af235);
{ 62 }
II(FpC, FpD, FpA, FpB, @FActiveBlock[ 2], S43, $2ad7d2bb);
{ 63 }
II(FpB, FpC, FpD, FpA, @FActiveBlock[ 9], S44, $eb86d391);
{ 64 }
Inc(FA, FAA);
Inc(FB, FBB);
Inc(FC, FCC);
Inc(FD, FDD);
FillChar(FActiveBlock, SizeOf(FActiveBlock), #0);
end;

procedure TMD5.HashCalc;
var
PStr: PChar;
begin
HashInit;
case FInputType of
itFile:
HashFile;
itByteArray:
HashBytes;
itString:
begin
PStr := StrAlloc(Length(FInputString) + 1);
try
StrPCopy(PStr, FInputString);
FInputLength := Length(FInputString);
FPInputArray := Pointer(PStr);
HashBytes;
finally
StrDispose(PStr);
end;
end;
end;
HashFinish;
end;

procedure TMD5.HashBytes;
var
Buffer: array[0..4159] of Byte;
Count64: Comp;
Index: Longword;
begin
Move(FPInputArray^, Buffer, FInputLength);
Count64 := FInputLength * 8;
Buffer[FInputLength] := $80;
Inc(FInputLength);
while (FInputLength mod 64) <> 56do
begin
Buffer[FInputLength] := 0;
Inc(FInputLength);
end;
Move(Count64, Buffer[FInputLength], SizeOf(Count64));
Index := 0;
Inc(FInputLength, 8);
repeat
Move(Buffer[Index], FActiveBlock, 64);
HashTransform;
Inc(Index, 64);
until Index = FInputLength;
end;

procedure TMD5.HashFile;
var
do
neFile: Boolean;
InputFile: file;
Count64: Comp;
Index, NumRead: Integer;
Buffer: array[0..4159] of Byte;
begin
do
neFile := False;
AssignFile(InputFile, FInputFilePath);
Reset(InputFile, 1);
Count64 := 0;
repeat
BlockRead(InputFile, Buffer, 4096, NumRead);
Count64 := Count64 + NumRead;
if NumRead <> 4096 then
begin
Buffer[NumRead] := $80;
Inc(NumRead);
while (NumRead mod 64) <> 56do
begin
Buffer[NumRead] := 0;
Inc(NumRead);
end;
Count64 := Count64 * 8;
Move(Count64, Buffer[NumRead], 8);
Inc(NumRead, 8);
do
neFile := True;
end;
Index := 0;
repeat
Move(Buffer[Index], FActiveBlock, 64);
HashTransform;
Inc(Index, 64);
until Index = NumRead;
untildo
neFile;
CloseFile(InputFile);
end;

procedure TMD5.HashFinish;
begin
FOutputDigest^.A := Longword(FpA^);
FOutputDigest^.B := Longword(FpB^);
FOutputDigest^.C := Longword(FpC^);
FOutputDigest^.D := Longword(FpD^);
end;

end.
我抄的
 
后退
顶部