{"id":292,"date":"2008-05-13T02:23:01","date_gmt":"2008-05-13T02:23:01","guid":{"rendered":"http:\/\/6teen.ru\/?p=86"},"modified":"2008-05-13T02:23:01","modified_gmt":"2008-05-13T02:23:01","slug":"1970","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=292","title":{"rendered":"\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b MD5"},"content":{"rendered":"<p>\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b MD5<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b MD5\n\n\u0410\u0432\u0442\u043e\u0440: Dimka Maslov\nWEB-\u0441\u0430\u0439\u0442: http:\/\/delphibase.endimus.com\n\n{******************************************************************}\n{ MD5 Hashsum Evaluation Unit For Borland Delphi }\n{ }\n{ Copyright c 2002 by Dimka Maslov }\n{ E-mail: mainbox@endimus.com, }\n{ Web-site: http:\/\/www.endimus.com }\n{ }\n{ Derived from the RSA Data Security, Inc. }\n{ MD5 Message-Digest Algorithm described in RFC 1321 }\n{ http:\/\/www.faqs.org\/rfcs\/rfc1321.html }\n{******************************************************************}\n\nunit md5;\n\ninterface\n\nuses Windows, SysUtils, Classes;\n\ntype\n{ \u0422\u0438\u043f TMD5Digest \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f\n\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b.\n\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\n\u043a\u0430\u043a \u043d\u0430\u0431\u043e\u0440 \u0438\u0437 4 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b, \u0438\u043b\u0438 \u043a\u0430\u043a\n\u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 16 \u0431\u0430\u0439\u0442 }\nPMD5Digest = ^TMD5Digest;\nTMD5Digest = record\ncase Integer of\n0: (A, B, C, D: LongInt);\n1: (v: array[0..15] of Byte);\nend;\n\n\/\/ \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u0438\nfunction MD5String(const S: string): TMD5Digest;\n\n\/\/ \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430\nfunction MD5File(const FileName: string): TMD5Digest;\n\n\/\/ \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b \u0434\u043b\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 Stream\nfunction MD5Stream(const Stream: TStream): TMD5Digest;\n\n\/\/ \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430\nfunction MD5Buffer(const Buffer; Size: Integer): TMD5Digest;\n\n\/\/ \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0437 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u044b\u0445 \u0446\u0438\u0444\u0440\nfunction MD5DigestToStr(const Digest: TMD5Digest): string;\n\n\/\/ \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\nfunction MD5DigestCompare(const Digest1, Digest2: TMD5Digest): Boolean;\n\nimplementation\n\n{\nCopyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All\nrights reserved.\n\nLicense to copy and use this software is granted provided that it\nis identified as the \"RSA Data Security, Inc. MD5 Message-Digest\nAlgorithm\" in all material mentioning or referencing this software\nor this function.\n\nLicense is also granted to make and use derivative works provided\nthat such works are identified as \"derived from the RSA Data\nSecurity, Inc. MD5 Message-Digest Algorithm\" in all material\nmentioning or referencing the derived work.\n\nRSA Data Security, Inc. makes no representations concerning either\nthe merchantability of this software or the suitability of this\nsoftware for any particular purpose. It is provided \"as is\"\nwithout express or implied warranty of any kind.\n\nThese notices must be retained in any copies of any part of this\ndocumentation and\/or software.\n}\n\ntype\nUINT4 = LongWord;\n\nPArray4UINT4 = ^TArray4UINT4;\nTArray4UINT4 = array[0..3] of UINT4;\nPArray2UINT4 = ^TArray2UINT4;\nTArray2UINT4 = array[0..1] of UINT4;\nPArray16Byte = ^TArray16Byte;\nTArray16Byte = array[0..15] of Byte;\nPArray64Byte = ^TArray64Byte;\nTArray64Byte = array[0..63] of Byte;\n\nPByteArray = ^TByteArray;\nTByteArray = array[0..0] of Byte;\n\nPUINT4Array = ^TUINT4Array;\nTUINT4Array = array[0..0] of UINT4;\n\nPMD5Context = ^TMD5Context;\nTMD5Context = record\nstate: TArray4UINT4;\ncount: TArray2UINT4;\nbuffer: TArray64Byte;\nend;\n\nconst\nS11 = 7;\nS12 = 12;\nS13 = 17;\nS14 = 22;\nS21 = 5;\nS22 = 9;\nS23 = 14;\nS24 = 20;\nS31 = 4;\nS32 = 11;\nS33 = 16;\nS34 = 23;\nS41 = 6;\nS42 = 10;\nS43 = 15;\nS44 = 21;\n\nvar\nPadding: TArray64Byte =\n($80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);\n\nfunction _F(x, y, z: UINT4): UINT4;\nbegin\nResult := (((x) and (y)) or ((not x) and (z)));\nend;\n\nfunction _G(x, y, z: UINT4): UINT4;\nbegin\nResult := (((x) and (z)) or ((y) and (not z)));\nend;\n\nfunction _H(x, y, z: UINT4): UINT4;\nbegin\nResult := ((x) xor (y) xor (z));\nend;\n\nfunction _I(x, y, z: UINT4): UINT4;\nbegin\nResult := ((y) xor ((x) or (not z)));\nend;\n\nfunction ROTATE_LEFT(x, n: UINT4): UINT4;\nbegin\nResult := (((x) shl (n)) or ((x) shr (32 - (n))));\nend;\n\nprocedure FF(var a: UINT4; b, c, d, x, s, ac: UINT4);\nbegin\na := a + _F(b, c, d) + x + ac;\na := ROTATE_LEFT(a, s);\na := a + b;\nend;\n\nprocedure GG(var a: UINT4; b, c, d, x, s, ac: UINT4);\nbegin\na := a + _G(b, c, d) + x + ac;\na := ROTATE_LEFT(a, s);\na := a + b;\nend;\n\nprocedure HH(var a: UINT4; b, c, d, x, s, ac: UINT4);\nbegin\na := a + _H(b, c, d) + x + ac;\na := ROTATE_LEFT(a, s);\na := a + b;\nend;\n\nprocedure II(var a: UINT4; b, c, d, x, s, ac: UINT4);\nbegin\na := a + _I(b, c, d) + x + ac;\na := ROTATE_LEFT(a, s);\na := a + b;\nend;\n\nprocedure MD5Encode(Output: PByteArray; Input: PUINT4Array; Len: LongWord);\nvar\ni, j: LongWord;\nbegin\nj := 0;\ni := 0;\nwhile j < Len do\nbegin\noutput[j] := Byte(input[i] and $FF);\noutput[j + 1] := Byte((input[i] shr 8) and $FF);\noutput[j + 2] := Byte((input[i] shr 16) and $FF);\noutput[j + 3] := Byte((input[i] shr 24) and $FF);\nInc(j, 4);\nInc(i);\nend;\n\nprocedure MD5Decode(Output: PUINT4Array; Input: PByteArray; Len: LongWord);\nvar\ni, j: LongWord;\nbegin\nj := 0;\ni := 0;\nwhile j < Len do\nbegin\nOutput[i] := UINT4(input[j]) or (UINT4(input[j + 1]) shl 8) or\n(UINT4(input[j + 2]) shl 16) or (UINT4(input[j + 3]) shl 24);\nInc(j, 4);\nInc(i);\nend;\n\nprocedure MD5_memcpy(Output: PByteArray; Input: PByteArray; Len: LongWord);\nbegin\nMove(Input^, Output^, Len);\nend;\n\nprocedure MD5_memset(Output: PByteArray; Value: Integer; Len: LongWord);\nbegin\nFillChar(Output^, Len, Byte(Value));\nend;\n\nprocedure MD5Transform(State: PArray4UINT4; Buffer: PArray64Byte);\nvar\na, b, c, d: UINT4;\nx: array[0..15] of UINT4;\nbegin\na := State[0];\nb := State[1];\nc := State[2];\nd := State[3];\nMD5Decode(PUINT4Array(@x), PByteArray(Buffer), 64);\n\nFF(a, b, c, d, x[0], S11, $D76AA478);\nFF(d, a, b, c, x[1], S12, $E8C7B756);\nFF(c, d, a, b, x[2], S13, $242070DB);\nFF(b, c, d, a, x[3], S14, $C1BDCEEE);\nFF(a, b, c, d, x[4], S11, $F57C0FAF);\nFF(d, a, b, c, x[5], S12, $4787C62A);\nFF(c, d, a, b, x[6], S13, $A8304613);\nFF(b, c, d, a, x[7], S14, $FD469501);\nFF(a, b, c, d, x[8], S11, $698098D8);\nFF(d, a, b, c, x[9], S12, $8B44F7AF);\nFF(c, d, a, b, x[10], S13, $FFFF5BB1);\nFF(b, c, d, a, x[11], S14, $895CD7BE);\nFF(a, b, c, d, x[12], S11, $6B901122);\nFF(d, a, b, c, x[13], S12, $FD987193);\nFF(c, d, a, b, x[14], S13, $A679438E);\nFF(b, c, d, a, x[15], S14, $49B40821);\n\nGG(a, b, c, d, x[1], S21, $F61E2562);\nGG(d, a, b, c, x[6], S22, $C040B340);\nGG(c, d, a, b, x[11], S23, $265E5A51);\nGG(b, c, d, a, x[0], S24, $E9B6C7AA);\nGG(a, b, c, d, x[5], S21, $D62F105D);\nGG(d, a, b, c, x[10], S22, $2441453);\nGG(c, d, a, b, x[15], S23, $D8A1E681);\nGG(b, c, d, a, x[4], S24, $E7D3FBC8);\nGG(a, b, c, d, x[9], S21, $21E1CDE6);\nGG(d, a, b, c, x[14], S22, $C33707D6);\nGG(c, d, a, b, x[3], S23, $F4D50D87);\n\nGG(b, c, d, a, x[8], S24, $455A14ED);\nGG(a, b, c, d, x[13], S21, $A9E3E905);\nGG(d, a, b, c, x[2], S22, $FCEFA3F8);\nGG(c, d, a, b, x[7], S23, $676F02D9);\nGG(b, c, d, a, x[12], S24, $8D2A4C8A);\n\nHH(a, b, c, d, x[5], S31, $FFFA3942);\nHH(d, a, b, c, x[8], S32, $8771F681);\nHH(c, d, a, b, x[11], S33, $6D9D6122);\nHH(b, c, d, a, x[14], S34, $FDE5380C);\nHH(a, b, c, d, x[1], S31, $A4BEEA44);\nHH(d, a, b, c, x[4], S32, $4BDECFA9);\nHH(c, d, a, b, x[7], S33, $F6BB4B60);\nHH(b, c, d, a, x[10], S34, $BEBFBC70);\nHH(a, b, c, d, x[13], S31, $289B7EC6);\nHH(d, a, b, c, x[0], S32, $EAA127FA);\nHH(c, d, a, b, x[3], S33, $D4EF3085);\nHH(b, c, d, a, x[6], S34, $4881D05);\nHH(a, b, c, d, x[9], S31, $D9D4D039);\nHH(d, a, b, c, x[12], S32, $E6DB99E5);\nHH(c, d, a, b, x[15], S33, $1FA27CF8);\nHH(b, c, d, a, x[2], S34, $C4AC5665);\n\nII(a, b, c, d, x[0], S41, $F4292244);\nII(d, a, b, c, x[7], S42, $432AFF97);\nII(c, d, a, b, x[14], S43, $AB9423A7);\nII(b, c, d, a, x[5], S44, $FC93A039);\nII(a, b, c, d, x[12], S41, $655B59C3);\nII(d, a, b, c, x[3], S42, $8F0CCC92);\nII(c, d, a, b, x[10], S43, $FFEFF47D);\nII(b, c, d, a, x[1], S44, $85845DD1);\nII(a, b, c, d, x[8], S41, $6FA87E4F);\nII(d, a, b, c, x[15], S42, $FE2CE6E0);\nII(c, d, a, b, x[6], S43, $A3014314);\nII(b, c, d, a, x[13], S44, $4E0811A1);\nII(a, b, c, d, x[4], S41, $F7537E82);\nII(d, a, b, c, x[11], S42, $BD3AF235);\nII(c, d, a, b, x[2], S43, $2AD7D2BB);\nII(b, c, d, a, x[9], S44, $EB86D391);\n\nInc(State[0], a);\nInc(State[1], b);\nInc(State[2], c);\nInc(State[3], d);\n\nMD5_memset(PByteArray(@x), 0, SizeOf(x));\nend;\n\nprocedure MD5Init(var Context: TMD5Context);\nbegin\nFillChar(Context, SizeOf(Context), 0);\nContext.state[0] := $67452301;\nContext.state[1] := $EFCDAB89;\nContext.state[2] := $98BADCFE;\nContext.state[3] := $10325476;\nend;\n\nprocedure MD5Update(var Context: TMD5Context; Input: PByteArray; InputLen:\nLongWord);\nvar\ni, index, partLen: LongWord;\n\nbegin\nindex := LongWord((context.count[0] shr 3) and $3F);\nInc(Context.count[0], UINT4(InputLen) shl 3);\nif Context.count[0] < UINT4(InputLen) shl 3 then\nInc(Context.count[1]);\nInc(Context.count[1], UINT4(InputLen) shr 29);\npartLen := 64 - index;\nif inputLen >= partLen then\nbegin\nMD5_memcpy(PByteArray(@Context.buffer[index]), Input, PartLen);\nMD5Transform(@Context.state, @Context.buffer);\ni := partLen;\nwhile i + 63 < inputLen do\nbegin\nMD5Transform(@Context.state, PArray64Byte(@Input[i]));\nInc(i, 64);\nend;\nindex := 0;\nend\nelse\ni := 0;\nMD5_memcpy(PByteArray(@Context.buffer[index]), PByteArray(@Input[i]), inputLen\n- i);\nend;\n\nprocedure MD5Final(var Digest: TMD5Digest; var Context: TMD5Context);\nvar\nbits: array[0..7] of Byte;\nindex, padLen: LongWord;\nbegin\nMD5Encode(PByteArray(@bits), PUINT4Array(@Context.count), 8);\nindex := LongWord((Context.count[0] shr 3) and $3F);\nif index < 56 then\npadLen := 56 - index\nelse\npadLen := 120 - index;\nMD5Update(Context, PByteArray(@PADDING), padLen);\nMD5Update(Context, PByteArray(@Bits), 8);\nMD5Encode(PByteArray(@Digest), PUINT4Array(@Context.state), 16);\nMD5_memset(PByteArray(@Context), 0, SizeOf(Context));\nend;\n\nfunction MD5DigestToStr(const Digest: TMD5Digest): string;\nvar\ni: Integer;\nbegin\nResult := '';\nfor i := 0 to 15 do\nResult := Result + IntToHex(Digest.v[i], 2);\nend;\n\nfunction MD5String(const S: string): TMD5Digest;\nbegin\nResult := MD5Buffer(PChar(S)^, Length(S));\nend;\n\nfunction MD5File(const FileName: string): TMD5Digest;\nvar\nF: TFileStream;\nbegin\nF := TFileStream.Create(FileName, fmOpenRead);\ntry\nResult := MD5Stream(F);\nfinally\nF.Free;\nend;\n\nfunction MD5Stream(const Stream: TStream): TMD5Digest;\nvar\nContext: TMD5Context;\nBuffer: array[0..4095] of Byte;\nSize: Integer;\nReadBytes: Integer;\nTotalBytes: Integer;\nSavePos: Integer;\nbegin\nMD5Init(Context);\nSize := Stream.Size;\nSavePos := Stream.Position;\nTotalBytes := 0;\ntry\nStream.Seek(0, soFromBeginning);\nrepeat\nReadBytes := Stream.Read(Buffer, SizeOf(Buffer));\nInc(TotalBytes, ReadBytes);\nMD5Update(Context, @Buffer, ReadBytes);\nuntil (ReadBytes = 0) or (TotalBytes = Size);\nfinally\nStream.Seek(SavePos, soFromBeginning);\nend;\nMD5Final(Result, Context);\nend;\n\nfunction MD5Buffer(const Buffer; Size: Integer): TMD5Digest;\nvar\nContext: TMD5Context;\nbegin\nMD5Init(Context);\nMD5Update(Context, PByteArray(@Buffer), Size);\nMD5Final(Result, Context);\nend;\n\nfunction MD5DigestCompare(const Digest1, Digest2: TMD5Digest): Boolean;\nbegin\nResult := False;\nif Digest1.A <> Digest2.A then\nExit;\nif Digest1.B <> Digest2.B then\nExit;\nif Digest1.C <> Digest2.C then\nExit;\nif Digest1.D <> Digest2.D then\nExit;\nResult := True;\nend;\n\nend.\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u0435\u0448-\u0441\u0443\u043c\u043c\u044b MD5<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[364,446],"tags":[543,204,1038],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/292"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}