﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-sunlea-文章分类-Delphi</title><link>http://www.blogjava.net/sunlea/category/1950.html</link><description>在语言的海洋里游动，在设计的大地上驰骋，在思想的蓝天里翱翔，在技术的太空中探索。</description><language>zh-cn</language><lastBuildDate>Thu, 01 Mar 2007 14:03:49 GMT</lastBuildDate><pubDate>Thu, 01 Mar 2007 14:03:49 GMT</pubDate><ttl>60</ttl><item><title>MD5加密</title><link>http://www.blogjava.net/sunlea/articles/6870.html</link><dc:creator>Sunlea 的空间</dc:creator><author>Sunlea 的空间</author><pubDate>Wed, 29 Jun 2005 04:47:00 GMT</pubDate><guid>http://www.blogjava.net/sunlea/articles/6870.html</guid><wfw:comment>http://www.blogjava.net/sunlea/comments/6870.html</wfw:comment><comments>http://www.blogjava.net/sunlea/articles/6870.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sunlea/comments/commentRss/6870.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sunlea/services/trackbacks/6870.html</trackback:ping><description><![CDATA[<P>// tabs = 2<BR>// -----------------------------------------------------------------------------------------------<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MD5 Message-Digest for Delphi 4<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Delphi 4 Unit implementing the<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RSA Data Security, Inc. MD5 Message-Digest Algorithm<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Implementation of Ronald L. Rivest's RFC 1321<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Copyright ?1997-1999 Medienagentur Fichtner &amp; Meyer<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Written by Matthias Fichtner<BR>//<BR>// -----------------------------------------------------------------------------------------------<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; See RFC 1321 for RSA Data Security's copyright and license notice!<BR>// -----------------------------------------------------------------------------------------------<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp; 14-Jun-97&nbsp; mf&nbsp; Implemented MD5 according to RFC 1321&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RFC 1321<BR>//&nbsp;&nbsp;&nbsp;&nbsp; 16-Jun-97&nbsp; mf&nbsp; Initial release of the compiled unit (no source code)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RFC 1321<BR>//&nbsp;&nbsp;&nbsp;&nbsp; 28-Feb-99&nbsp; mf&nbsp; Added MD5Match function for comparing two digests&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RFC 1321<BR>//&nbsp;&nbsp;&nbsp;&nbsp; 13-Sep-99&nbsp; mf&nbsp; Reworked the entire unit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RFC 1321<BR>//&nbsp;&nbsp;&nbsp;&nbsp; 17-Sep-99&nbsp; mf&nbsp; Reworked the "Test Driver" project&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RFC 1321<BR>//&nbsp;&nbsp;&nbsp;&nbsp; 19-Sep-99&nbsp; mf&nbsp; Release of sources for MD5 unit and "Test Driver" project&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RFC 1321<BR>//<BR>// -----------------------------------------------------------------------------------------------<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The latest release of md5.pas will always be available from<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the distribution site at: <A href="http://www.fichtner.net/delphi/md5/"><FONT color=#000080>http://www.fichtner.net/delphi/md5/</FONT></A><BR>// -----------------------------------------------------------------------------------------------<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Please send questions, bug reports and suggestions<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; regarding this code to: <A href="mailto:mfichtner@fichtner-meyer.com"><FONT color=#000080>mfichtner@fichtner-meyer.com</FONT></A><BR>// -----------------------------------------------------------------------------------------------<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This code is provided "as is" without express or<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; implied warranty of any kind. Use it at your own risk.<BR>// -----------------------------------------------------------------------------------------------</P>
<P>unit md5;</P>
<P>// -----------------------------------------------------------------------------------------------<BR>INTERFACE<BR>// -----------------------------------------------------------------------------------------------</P>
<P>uses<BR>&nbsp;Windows;</P>
<P>type<BR>&nbsp;MD5Count = array[0..1] of DWORD;<BR>&nbsp;MD5State = array[0..3] of DWORD;<BR>&nbsp;MD5Block = array[0..15] of DWORD;<BR>&nbsp;MD5CBits = array[0..7] of byte;<BR>&nbsp;MD5Digest = array[0..15] of byte;<BR>&nbsp;MD5Buffer = array[0..63] of byte;<BR>&nbsp;MD5Context = record<BR>&nbsp;&nbsp;State: MD5State;<BR>&nbsp;&nbsp;Count: MD5Count;<BR>&nbsp;&nbsp;Buffer: MD5Buffer;<BR>&nbsp;end;<BR>{<BR>1、 MD5String、MD5File、MD5Print、MD5Match这四个函数是供调用的。其他是用来辅助这几个函数的子函数。<BR>2、MD5String为加密字符串。<BR>3、MD5File为加密这个文件。<BR>4、MD5Print是将加密后的密文转换成字符串。<BR>5、MD5Match是用来比较密文是否一致。</P>
<P>加密字符串aaa&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MD5String('aaa')<BR>将加密后的aaa显示出来&nbsp;&nbsp;&nbsp;&nbsp; MD5Print(MD5String('aaa'))<BR>比较两次密文是否一致：&nbsp;&nbsp;&nbsp; MD5Match(MD5String('第一次明文'),MD5String('第二次输入的明文'))</P>
<P>}</P>
<P>procedure MD5Init(var Context: MD5Context);<BR>procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);<BR>procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);</P>
<P>function MD5String(M: string): MD5Digest;<BR>function MD5File(N: string): MD5Digest;<BR>function MD5Print(D: MD5Digest): string;</P>
<P>function MD5Match(D1, D2: MD5Digest): boolean;</P>
<P>// -----------------------------------------------------------------------------------------------<BR>IMPLEMENTATION<BR>// -----------------------------------------------------------------------------------------------</P>
<P>var<BR>&nbsp;PADDING: MD5Buffer = (<BR>&nbsp;&nbsp;$80, $00, $00, $00, $00, $00, $00, $00,<BR>&nbsp;&nbsp;$00, $00, $00, $00, $00, $00, $00, $00,<BR>&nbsp;&nbsp;$00, $00, $00, $00, $00, $00, $00, $00,<BR>&nbsp;&nbsp;$00, $00, $00, $00, $00, $00, $00, $00,<BR>&nbsp;&nbsp;$00, $00, $00, $00, $00, $00, $00, $00,<BR>&nbsp;&nbsp;$00, $00, $00, $00, $00, $00, $00, $00,<BR>&nbsp;&nbsp;$00, $00, $00, $00, $00, $00, $00, $00,<BR>&nbsp;&nbsp;$00, $00, $00, $00, $00, $00, $00, $00<BR>&nbsp;);</P>
<P>function F(x, y, z: DWORD): DWORD;<BR>begin<BR>&nbsp;Result := (x and y) or ((not x) and z);<BR>end;</P>
<P>function G(x, y, z: DWORD): DWORD;<BR>begin<BR>&nbsp;Result := (x and z) or (y and (not z));<BR>end;</P>
<P>function H(x, y, z: DWORD): DWORD;<BR>begin<BR>&nbsp;Result := x xor y xor z;<BR>end;</P>
<P>function I(x, y, z: DWORD): DWORD;<BR>begin<BR>&nbsp;Result := y xor (x or (not z));<BR>end;</P>
<P>procedure rot(var x: DWORD; n: BYTE);<BR>begin<BR>&nbsp;x := (x shl n) or (x shr (32 - n));<BR>end;</P>
<P>procedure FF(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);<BR>begin<BR>&nbsp;inc(a, F(b, c, d) + x + ac);<BR>&nbsp;rot(a, s);<BR>&nbsp;inc(a, b);<BR>end;</P>
<P>procedure GG(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);<BR>begin<BR>&nbsp;inc(a, G(b, c, d) + x + ac);<BR>&nbsp;rot(a, s);<BR>&nbsp;inc(a, b);<BR>end;</P>
<P>procedure HH(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);<BR>begin<BR>&nbsp;inc(a, H(b, c, d) + x + ac);<BR>&nbsp;rot(a, s);<BR>&nbsp;inc(a, b);<BR>end;</P>
<P>procedure II(var a: DWORD; b, c, d, x: DWORD; s: BYTE; ac: DWORD);<BR>begin<BR>&nbsp;inc(a, I(b, c, d) + x + ac);<BR>&nbsp;rot(a, s);<BR>&nbsp;inc(a, b);<BR>end;</P>
<P>// -----------------------------------------------------------------------------------------------</P>
<P>// Encode Count bytes at Source into (Count / 4) DWORDs at Target<BR>procedure Encode(Source, Target: pointer; Count: longword);<BR>var<BR>&nbsp;S: PByte;<BR>&nbsp;T: PDWORD;<BR>&nbsp;I: longword;<BR>begin<BR>&nbsp;S := Source;<BR>&nbsp;T := Target;<BR>&nbsp;for I := 1 to Count div 4 do begin<BR>&nbsp;&nbsp;T^ := S^;<BR>&nbsp;&nbsp;inc(S);<BR>&nbsp;&nbsp;T^ := T^ or (S^ shl 8);<BR>&nbsp;&nbsp;inc(S);<BR>&nbsp;&nbsp;T^ := T^ or (S^ shl 16);<BR>&nbsp;&nbsp;inc(S);<BR>&nbsp;&nbsp;T^ := T^ or (S^ shl 24);<BR>&nbsp;&nbsp;inc(S);<BR>&nbsp;&nbsp;inc(T);<BR>&nbsp;end;<BR>end;</P>
<P>// Decode Count DWORDs at Source into (Count * 4) Bytes at Target<BR>procedure Decode(Source, Target: pointer; Count: longword);<BR>var<BR>&nbsp;S: PDWORD;<BR>&nbsp;T: PByte;<BR>&nbsp;I: longword;<BR>begin<BR>&nbsp;S := Source;<BR>&nbsp;T := Target;<BR>&nbsp;for I := 1 to Count do begin<BR>&nbsp;&nbsp;T^ := S^ and $ff;<BR>&nbsp;&nbsp;inc(T);<BR>&nbsp;&nbsp;T^ := (S^ shr 8) and $ff;<BR>&nbsp;&nbsp;inc(T);<BR>&nbsp;&nbsp;T^ := (S^ shr 16) and $ff;<BR>&nbsp;&nbsp;inc(T);<BR>&nbsp;&nbsp;T^ := (S^ shr 24) and $ff;<BR>&nbsp;&nbsp;inc(T);<BR>&nbsp;&nbsp;inc(S);<BR>&nbsp;end;<BR>end;</P>
<P>// Transform State according to first 64 bytes at Buffer<BR>procedure Transform(Buffer: pointer; var State: MD5State);<BR>var<BR>&nbsp;a, b, c, d: DWORD;<BR>&nbsp;Block: MD5Block;<BR>begin<BR>&nbsp;Encode(Buffer, @Block, 64);<BR>&nbsp;a := State[0];<BR>&nbsp;b := State[1];<BR>&nbsp;c := State[2];<BR>&nbsp;d := State[3];<BR>&nbsp;FF (a, b, c, d, Block[ 0],&nbsp; 7, $d76aa478);<BR>&nbsp;FF (d, a, b, c, Block[ 1], 12, $e8c7b756);<BR>&nbsp;FF (c, d, a, b, Block[ 2], 17, $242070db);<BR>&nbsp;FF (b, c, d, a, Block[ 3], 22, $c1bdceee);<BR>&nbsp;FF (a, b, c, d, Block[ 4],&nbsp; 7, $f57c0faf);<BR>&nbsp;FF (d, a, b, c, Block[ 5], 12, $4787c62a);<BR>&nbsp;FF (c, d, a, b, Block[ 6], 17, $a8304613);<BR>&nbsp;FF (b, c, d, a, Block[ 7], 22, $fd469501);<BR>&nbsp;FF (a, b, c, d, Block[ 8],&nbsp; 7, $698098d8);<BR>&nbsp;FF (d, a, b, c, Block[ 9], 12, $8b44f7af);<BR>&nbsp;FF (c, d, a, b, Block[10], 17, $ffff5bb1);<BR>&nbsp;FF (b, c, d, a, Block[11], 22, $895cd7be);<BR>&nbsp;FF (a, b, c, d, Block[12],&nbsp; 7, $6b901122);<BR>&nbsp;FF (d, a, b, c, Block[13], 12, $fd987193);<BR>&nbsp;FF (c, d, a, b, Block[14], 17, $a679438e);<BR>&nbsp;FF (b, c, d, a, Block[15], 22, $49b40821);<BR>&nbsp;GG (a, b, c, d, Block[ 1],&nbsp; 5, $f61e2562);<BR>&nbsp;GG (d, a, b, c, Block[ 6],&nbsp; 9, $c040b340);<BR>&nbsp;GG (c, d, a, b, Block[11], 14, $265e5a51);<BR>&nbsp;GG (b, c, d, a, Block[ 0], 20, $e9b6c7aa);<BR>&nbsp;GG (a, b, c, d, Block[ 5],&nbsp; 5, $d62f105d);<BR>&nbsp;GG (d, a, b, c, Block[10],&nbsp; 9,&nbsp; $2441453);<BR>&nbsp;GG (c, d, a, b, Block[15], 14, $d8a1e681);<BR>&nbsp;GG (b, c, d, a, Block[ 4], 20, $e7d3fbc8);<BR>&nbsp;GG (a, b, c, d, Block[ 9],&nbsp; 5, $21e1cde6);<BR>&nbsp;GG (d, a, b, c, Block[14],&nbsp; 9, $c33707d6);<BR>&nbsp;GG (c, d, a, b, Block[ 3], 14, $f4d50d87);<BR>&nbsp;GG (b, c, d, a, Block[ 8], 20, $455a14ed);<BR>&nbsp;GG (a, b, c, d, Block[13],&nbsp; 5, $a9e3e905);<BR>&nbsp;GG (d, a, b, c, Block[ 2],&nbsp; 9, $fcefa3f8);<BR>&nbsp;GG (c, d, a, b, Block[ 7], 14, $676f02d9);<BR>&nbsp;GG (b, c, d, a, Block[12], 20, $8d2a4c8a);<BR>&nbsp;HH (a, b, c, d, Block[ 5],&nbsp; 4, $fffa3942);<BR>&nbsp;HH (d, a, b, c, Block[ 8], 11, $8771f681);<BR>&nbsp;HH (c, d, a, b, Block[11], 16, $6d9d6122);<BR>&nbsp;HH (b, c, d, a, Block[14], 23, $fde5380c);<BR>&nbsp;HH (a, b, c, d, Block[ 1],&nbsp; 4, $a4beea44);<BR>&nbsp;HH (d, a, b, c, Block[ 4], 11, $4bdecfa9);<BR>&nbsp;HH (c, d, a, b, Block[ 7], 16, $f6bb4b60);<BR>&nbsp;HH (b, c, d, a, Block[10], 23, $bebfbc70);<BR>&nbsp;HH (a, b, c, d, Block[13],&nbsp; 4, $289b7ec6);<BR>&nbsp;HH (d, a, b, c, Block[ 0], 11, $eaa127fa);<BR>&nbsp;HH (c, d, a, b, Block[ 3], 16, $d4ef3085);<BR>&nbsp;HH (b, c, d, a, Block[ 6], 23,&nbsp; $4881d05);<BR>&nbsp;HH (a, b, c, d, Block[ 9],&nbsp; 4, $d9d4d039);<BR>&nbsp;HH (d, a, b, c, Block[12], 11, $e6db99e5);<BR>&nbsp;HH (c, d, a, b, Block[15], 16, $1fa27cf8);<BR>&nbsp;HH (b, c, d, a, Block[ 2], 23, $c4ac5665);<BR>&nbsp;II (a, b, c, d, Block[ 0],&nbsp; 6, $f4292244);<BR>&nbsp;II (d, a, b, c, Block[ 7], 10, $432aff97);<BR>&nbsp;II (c, d, a, b, Block[14], 15, $ab9423a7);<BR>&nbsp;II (b, c, d, a, Block[ 5], 21, $fc93a039);<BR>&nbsp;II (a, b, c, d, Block[12],&nbsp; 6, $655b59c3);<BR>&nbsp;II (d, a, b, c, Block[ 3], 10, $8f0ccc92);<BR>&nbsp;II (c, d, a, b, Block[10], 15, $ffeff47d);<BR>&nbsp;II (b, c, d, a, Block[ 1], 21, $85845dd1);<BR>&nbsp;II (a, b, c, d, Block[ 8],&nbsp; 6, $6fa87e4f);<BR>&nbsp;II (d, a, b, c, Block[15], 10, $fe2ce6e0);<BR>&nbsp;II (c, d, a, b, Block[ 6], 15, $a3014314);<BR>&nbsp;II (b, c, d, a, Block[13], 21, $4e0811a1);<BR>&nbsp;II (a, b, c, d, Block[ 4],&nbsp; 6, $f7537e82);<BR>&nbsp;II (d, a, b, c, Block[11], 10, $bd3af235);<BR>&nbsp;II (c, d, a, b, Block[ 2], 15, $2ad7d2bb);<BR>&nbsp;II (b, c, d, a, Block[ 9], 21, $eb86d391);<BR>&nbsp;inc(State[0], a);<BR>&nbsp;inc(State[1], b);<BR>&nbsp;inc(State[2], c);<BR>&nbsp;inc(State[3], d);<BR>end;</P>
<P>// -----------------------------------------------------------------------------------------------</P>
<P>// Initialize given Context<BR>procedure MD5Init(var Context: MD5Context);<BR>begin<BR>&nbsp;with Context do begin<BR>&nbsp;&nbsp;State[0] := $67452301;<BR>&nbsp;&nbsp;State[1] := $efcdab89;<BR>&nbsp;&nbsp;State[2] := $98badcfe;<BR>&nbsp;&nbsp;State[3] := $10325476;<BR>&nbsp;&nbsp;Count[0] := 0;<BR>&nbsp;&nbsp;Count[1] := 0;<BR>&nbsp;&nbsp;ZeroMemory(@Buffer, SizeOf(MD5Buffer));<BR>&nbsp;end;<BR>end;</P>
<P>// Update given Context to include Length bytes of Input<BR>procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);<BR>var<BR>&nbsp;Index: longword;<BR>&nbsp;PartLen: longword;<BR>&nbsp;I: longword;<BR>begin<BR>&nbsp;with Context do begin<BR>&nbsp;&nbsp;Index := (Count[0] shr 3) and $3f;<BR>&nbsp;&nbsp;inc(Count[0], Length shl 3);<BR>&nbsp;&nbsp;if Count[0] &lt; (Length shl 3) then inc(Count[1]);<BR>&nbsp;&nbsp;inc(Count[1], Length shr 29);<BR>&nbsp;end;<BR>&nbsp;PartLen := 64 - Index;<BR>&nbsp;if Length &gt;= PartLen then begin<BR>&nbsp;&nbsp;CopyMemory(@Context.Buffer[Index], Input, PartLen);<BR>&nbsp;&nbsp;Transform(@Context.Buffer, Context.State);<BR>&nbsp;&nbsp;I := PartLen;<BR>&nbsp;&nbsp;while I + 63 &lt; Length do begin<BR>&nbsp;&nbsp;&nbsp;Transform(@Input[I], Context.State);<BR>&nbsp;&nbsp;&nbsp;inc(I, 64);<BR>&nbsp;&nbsp;end;<BR>&nbsp;&nbsp;Index := 0;<BR>&nbsp;end else I := 0;<BR>&nbsp;CopyMemory(@Context.Buffer[Index], @Input[I], Length - I);<BR>end;</P>
<P>// Finalize given Context, create Digest and zeroize Context<BR>procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);<BR>var<BR>&nbsp;Bits: MD5CBits;<BR>&nbsp;Index: longword;<BR>&nbsp;PadLen: longword;<BR>begin<BR>&nbsp;Decode(@Context.Count, @Bits, 2);<BR>&nbsp;Index := (Context.Count[0] shr 3) and $3f;<BR>&nbsp;if Index &lt; 56 then PadLen := 56 - Index else PadLen := 120 - Index;<BR>&nbsp;MD5Update(Context, @PADDING, PadLen);<BR>&nbsp;MD5Update(Context, @Bits, 8);<BR>&nbsp;Decode(@Context.State, @Digest, 4);<BR>&nbsp;ZeroMemory(@Context, SizeOf(MD5Context));<BR>end;</P>
<P>// -----------------------------------------------------------------------------------------------</P>
<P>// Create digest of given Message<BR>function MD5String(M: string): MD5Digest;<BR>var<BR>&nbsp;Context: MD5Context;<BR>begin<BR>&nbsp;MD5Init(Context);<BR>&nbsp;MD5Update(Context, pChar(M), length(M));<BR>&nbsp;MD5Final(Context, Result);<BR>end;</P>
<P>// Create digest of file with given Name<BR>function MD5File(N: string): MD5Digest;<BR>var<BR>&nbsp;FileHandle: THandle;<BR>&nbsp;MapHandle: THandle;<BR>&nbsp;ViewPointer: pointer;<BR>&nbsp;Context: MD5Context;<BR>begin<BR>&nbsp;MD5Init(Context);<BR>&nbsp;FileHandle := CreateFile(pChar(N), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,<BR>&nbsp;&nbsp;nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0);<BR>&nbsp;if FileHandle &lt;&gt; INVALID_HANDLE_VALUE then try<BR>&nbsp;&nbsp;MapHandle := CreateFileMapping(FileHandle, nil, PAGE_READONLY, 0, 0, nil);<BR>&nbsp;&nbsp;if MapHandle &lt;&gt; 0 then try<BR>&nbsp;&nbsp;&nbsp;ViewPointer := MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0);<BR>&nbsp;&nbsp;&nbsp;if ViewPointer &lt;&gt; nil then try<BR>&nbsp;&nbsp;&nbsp;&nbsp;MD5Update(Context, ViewPointer, GetFileSize(FileHandle, nil));<BR>&nbsp;&nbsp;&nbsp;finally<BR>&nbsp;&nbsp;&nbsp;&nbsp;UnmapViewOfFile(ViewPointer);<BR>&nbsp;&nbsp;&nbsp;end;<BR>&nbsp;&nbsp;finally<BR>&nbsp;&nbsp;&nbsp;CloseHandle(MapHandle);<BR>&nbsp;&nbsp;end;<BR>&nbsp;finally<BR>&nbsp;&nbsp;CloseHandle(FileHandle);<BR>&nbsp;end;<BR>&nbsp;MD5Final(Context, Result);<BR>end;</P>
<P>// Create hex representation of given Digest<BR>function MD5Print(D: MD5Digest): string;<BR>var<BR>&nbsp;I: byte;<BR>const<BR>&nbsp;Digits: array[0..15] of char =<BR>&nbsp;&nbsp;('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');<BR>begin<BR>&nbsp;Result := '';<BR>&nbsp;for I := 0 to 15 do Result := Result + Digits[(D[I] shr 4) and $0f] + Digits[D[I] and $0f];<BR>end;</P>
<P>// -----------------------------------------------------------------------------------------------</P>
<P>// Compare two Digests<BR>function MD5Match(D1, D2: MD5Digest): boolean;<BR>var<BR>&nbsp;I: byte;<BR>begin<BR>&nbsp;I := 0;<BR>&nbsp;Result := TRUE;<BR>&nbsp;while Result and (I &lt; 16) do begin<BR>&nbsp;&nbsp;Result := D1[I] = D2[I];<BR>&nbsp;&nbsp;inc(I);<BR>&nbsp;end;<BR>end;</P>
<P>end.<BR></P><img src ="http://www.blogjava.net/sunlea/aggbug/6870.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sunlea/" target="_blank">Sunlea 的空间</a> 2005-06-29 12:47 <a href="http://www.blogjava.net/sunlea/articles/6870.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DES加密解密代码</title><link>http://www.blogjava.net/sunlea/articles/6869.html</link><dc:creator>Sunlea 的空间</dc:creator><author>Sunlea 的空间</author><pubDate>Wed, 29 Jun 2005 04:46:00 GMT</pubDate><guid>http://www.blogjava.net/sunlea/articles/6869.html</guid><wfw:comment>http://www.blogjava.net/sunlea/comments/6869.html</wfw:comment><comments>http://www.blogjava.net/sunlea/articles/6869.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sunlea/comments/commentRss/6869.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sunlea/services/trackbacks/6869.html</trackback:ping><description><![CDATA[<SPAN>
<P>unit DESCrypt;</P>
<P>interface<BR>uses<BR>&nbsp; SysUtils;</P>
<P>function EnCrypt(aStr: string; acKey: string ): string; //加密字符串-------------------------------<BR>function DeCrypt(aStr: string; acKey: string ): string; //解密字符串-------------------------------</P>
<P>implementation</P>
<P>type<BR>&nbsp; TByte32 = array[1..32] of Byte;<BR>&nbsp; TSData&nbsp; = array[0..63] of Byte;<BR>&nbsp; TBlock = array[0..7] of Byte;</P>
<P>const<BR>&nbsp; SA1: TSData =<BR>&nbsp; (1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1,<BR>&nbsp;&nbsp;&nbsp; 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1);<BR>&nbsp; SA2: TSData =<BR>&nbsp; (1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0,<BR>&nbsp;&nbsp;&nbsp; 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1);<BR>&nbsp; SA3: TSData =<BR>&nbsp; (1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0,<BR>&nbsp;&nbsp;&nbsp; 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 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,<BR>&nbsp;&nbsp;&nbsp; 42, 53, 32, 38, 48, 56, 31, 41, 52, 46, 34, 49, 45, 50, 40, 29, 35, 54, 47, 43, 51, 37, 30, 33),<BR>&nbsp;&nbsp;&nbsp; (16, 19, 13, 26, 3, 7, 5, 2, 17, 8, 23, 12, 25, 21, 14, 6, 28, 10, 18, 9, 1, 22, 15, 4,<BR>&nbsp;&nbsp;&nbsp; 43, 54, 33, 39, 49, 29, 32, 42, 53, 47, 35, 50, 46, 51, 41, 30, 36, 55, 48, 44, 52, 38, 31, 34),<BR>&nbsp;&nbsp;&nbsp; (18, 21, 15, 28, 5, 9, 7, 4, 19, 10, 25, 14, 27, 23, 16, 8, 2, 12, 20, 11, 3, 24, 17, 6,<BR>&nbsp;&nbsp;&nbsp; 45, 56, 35, 41, 51, 31, 34, 44, 55, 49, 37, 52, 48, 53, 43, 32, 38, 29, 50, 46, 54, 40, 33, 36),<BR>&nbsp;&nbsp;&nbsp; (20, 23, 17, 2, 7, 11, 9, 6, 21, 12, 27, 16, 1, 25, 18, 10, 4, 14, 22, 13, 5, 26, 19, 8,<BR>&nbsp;&nbsp;&nbsp; 47, 30, 37, 43, 53, 33, 36, 46, 29, 51, 39, 54, 50, 55, 45, 34, 40, 31, 52, 48, 56, 42, 35, 38),<BR>&nbsp;&nbsp;&nbsp; (22, 25, 19, 4, 9, 13, 11, 8, 23, 14, 1, 18, 3, 27, 20, 12, 6, 16, 24, 15, 7, 28, 21, 10,<BR>&nbsp;&nbsp;&nbsp; 49, 32, 39, 45, 55, 35, 38, 48, 31, 53, 41, 56, 52, 29, 47, 36, 42, 33, 54, 50, 30, 44, 37, 40),<BR>&nbsp;&nbsp;&nbsp; (24, 27, 21, 6, 11, 15, 13, 10, 25, 16, 3, 20, 5, 1, 22, 14, 8, 18, 26, 17, 9, 2, 23, 12,<BR>&nbsp;&nbsp;&nbsp; 51, 34, 41, 47, 29, 37, 40, 50, 33, 55, 43, 30, 54, 31, 49, 38, 44, 35, 56, 52, 32, 46, 39, 42),<BR>&nbsp;&nbsp;&nbsp; (26, 1, 23, 8, 13, 17, 15, 12, 27, 18, 5, 22, 7, 3, 24, 16, 10, 20, 28, 19, 11, 4, 25, 14,<BR>&nbsp;&nbsp;&nbsp; 53, 36, 43, 49, 31, 39, 42, 52, 35, 29, 45, 32, 56, 33, 51, 40, 46, 37, 30, 54, 34, 48, 41, 44),<BR>&nbsp;&nbsp;&nbsp; (28, 3, 25, 10, 15, 19, 17, 14, 1, 20, 7, 24, 9, 5, 26, 18, 12, 22, 2, 21, 13, 6, 27, 16,<BR>&nbsp;&nbsp;&nbsp; 55, 38, 45, 51, 33, 41, 44, 54, 37, 31, 47, 34, 30, 35, 53, 42, 48, 39, 32, 56, 36, 50, 43, 46),<BR>&nbsp;&nbsp;&nbsp; (1, 4, 26, 11, 16, 20, 18, 15, 2, 21, 8, 25, 10, 6, 27, 19, 13, 23, 3, 22, 14, 7, 28, 17,<BR>&nbsp;&nbsp;&nbsp; 56, 39, 46, 52, 34, 42, 45, 55, 38, 32, 48, 35, 31, 36, 54, 43, 49, 40, 33, 29, 37, 51, 44, 47),<BR>&nbsp;&nbsp;&nbsp; (3, 6, 28, 13, 18, 22, 20, 17, 4, 23, 10, 27, 12, 8, 1, 21, 15, 25, 5, 24, 16, 9, 2, 19,<BR>&nbsp;&nbsp;&nbsp; 30, 41, 48, 54, 36, 44, 47, 29, 40, 34, 50, 37, 33, 38, 56, 45, 51, 42, 35, 31, 39, 53, 46, 49),<BR>&nbsp;&nbsp;&nbsp; (5, 8, 2, 15, 20, 24, 22, 19, 6, 25, 12, 1, 14, 10, 3, 23, 17, 27, 7, 26, 18, 11, 4, 21,<BR>&nbsp;&nbsp;&nbsp; 32, 43, 50, 56, 38, 46, 49, 31, 42, 36, 52, 39, 35, 40, 30, 47, 53, 44, 37, 33, 41, 55, 48, 51),<BR>&nbsp;&nbsp;&nbsp; (7, 10, 4, 17, 22, 26, 24, 21, 8, 27, 14, 3, 16, 12, 5, 25, 19, 1, 9, 28, 20, 13, 6, 23,<BR>&nbsp;&nbsp;&nbsp; 34, 45, 52, 30, 40, 48, 51, 33, 44, 38, 54, 41, 37, 42, 32, 49, 55, 46, 39, 35, 43, 29, 50, 53),<BR>&nbsp;&nbsp;&nbsp; (9, 12, 6, 19, 24, 28, 26, 23, 10, 1, 16, 5, 18, 14, 7, 27, 21, 3, 11, 2, 22, 15, 8, 25,<BR>&nbsp;&nbsp;&nbsp; 36, 47, 54, 32, 42, 50, 53, 35, 46, 40, 56, 43, 39, 44, 34, 51, 29, 48, 41, 37, 45, 31, 52, 55),<BR>&nbsp;&nbsp;&nbsp; (11, 14, 8, 21, 26, 2, 28, 25, 12, 3, 18, 7, 20, 16, 9, 1, 23, 5, 13, 4, 24, 17, 10, 27,<BR>&nbsp;&nbsp;&nbsp; 38, 49, 56, 34, 44, 52, 55, 37, 48, 42, 30, 45, 41, 46, 36, 53, 31, 50, 43, 39, 47, 33, 54, 29),<BR>&nbsp;&nbsp;&nbsp; (13, 16, 10, 23, 28, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1,<BR>&nbsp;&nbsp;&nbsp; 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 56, 31),<BR>&nbsp;&nbsp;&nbsp; (14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,<BR>&nbsp;&nbsp;&nbsp; 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32));</P>
<P>var<BR>&nbsp; G: array[1..16, 1..48] of Byte;<BR>&nbsp; L, R, F: TByte32;<BR>&nbsp; C: array[1..56] of Byte;</P>
<P>procedure DES_Init(Key: TBlock; FCode: Boolean);<BR>var<BR>&nbsp; n, h: Byte;<BR>begin<BR>&nbsp; C[1]&nbsp; := Ord(Key[7] and 128 &gt; 0); C[29] := Ord(Key[7] and 2 &gt; 0);<BR>&nbsp; C[2]&nbsp; := Ord(Key[6] and 128 &gt; 0); C[30] := Ord(Key[6] and 2 &gt; 0);<BR>&nbsp; C[3]&nbsp; := Ord(Key[5] and 128 &gt; 0); C[31] := Ord(Key[5] and 2 &gt; 0);<BR>&nbsp; C[4]&nbsp; := Ord(Key[4] and 128 &gt; 0); C[32] := Ord(Key[4] and 2 &gt; 0);<BR>&nbsp; C[5]&nbsp; := Ord(Key[3] and 128 &gt; 0); C[33] := Ord(Key[3] and 2 &gt; 0);<BR>&nbsp; C[6]&nbsp; := Ord(Key[2] and 128 &gt; 0); C[34] := Ord(Key[2] and 2 &gt; 0);<BR>&nbsp; C[7]&nbsp; := Ord(Key[1] and 128 &gt; 0); C[35] := Ord(Key[1] and 2 &gt; 0);<BR>&nbsp; C[8]&nbsp; := Ord(Key[0] and 128 &gt; 0); C[36] := Ord(Key[0] and 2 &gt; 0);</P>
<P>&nbsp; C[9]&nbsp; := Ord(Key[7] and 64 &gt; 0);&nbsp; C[37] := Ord(Key[7] and 4 &gt; 0);<BR>&nbsp; C[10] := Ord(Key[6] and 64 &gt; 0);&nbsp; C[38] := Ord(Key[6] and 4 &gt; 0);<BR>&nbsp; C[11] := Ord(Key[5] and 64 &gt; 0);&nbsp; C[39] := Ord(Key[5] and 4 &gt; 0);<BR>&nbsp; C[12] := Ord(Key[4] and 64 &gt; 0);&nbsp; C[40] := Ord(Key[4] and 4 &gt; 0);<BR>&nbsp; C[13] := Ord(Key[3] and 64 &gt; 0);&nbsp; C[41] := Ord(Key[3] and 4 &gt; 0);<BR>&nbsp; C[14] := Ord(Key[2] and 64 &gt; 0);&nbsp; C[42] := Ord(Key[2] and 4 &gt; 0);<BR>&nbsp; C[15] := Ord(Key[1] and 64 &gt; 0);&nbsp; C[43] := Ord(Key[1] and 4 &gt; 0);<BR>&nbsp; C[16] := Ord(Key[0] and 64 &gt; 0);&nbsp; C[44] := Ord(Key[0] and 4 &gt; 0);</P>
<P>&nbsp; C[17] := Ord(Key[7] and 32 &gt; 0);&nbsp; C[45] := Ord(Key[7] and 8 &gt; 0);<BR>&nbsp; C[18] := Ord(Key[6] and 32 &gt; 0);&nbsp; C[46] := Ord(Key[6] and 8 &gt; 0);<BR>&nbsp; C[19] := Ord(Key[5] and 32 &gt; 0);&nbsp; C[47] := Ord(Key[5] and 8 &gt; 0);<BR>&nbsp; C[20] := Ord(Key[4] and 32 &gt; 0);&nbsp; C[48] := Ord(Key[4] and 8 &gt; 0);<BR>&nbsp; C[21] := Ord(Key[3] and 32 &gt; 0);&nbsp; C[49] := Ord(Key[3] and 8 &gt; 0);<BR>&nbsp; C[22] := Ord(Key[2] and 32 &gt; 0);&nbsp; C[50] := Ord(Key[2] and 8 &gt; 0);<BR>&nbsp; C[23] := Ord(Key[1] and 32 &gt; 0);&nbsp; C[51] := Ord(Key[1] and 8 &gt; 0);<BR>&nbsp; C[24] := Ord(Key[0] and 32 &gt; 0);&nbsp; C[52] := Ord(Key[0] and 8 &gt; 0);</P>
<P>&nbsp; C[25] := Ord(Key[7] and 16 &gt; 0);&nbsp; C[53] := Ord(Key[3] and 16 &gt; 0);<BR>&nbsp; C[26] := Ord(Key[6] and 16 &gt; 0);&nbsp; C[54] := Ord(Key[2] and 16 &gt; 0);<BR>&nbsp; C[27] := Ord(Key[5] and 16 &gt; 0);&nbsp; C[55] := Ord(Key[1] and 16 &gt; 0);<BR>&nbsp; C[28] := Ord(Key[4] and 16 &gt; 0);&nbsp; C[56] := Ord(Key[0] and 16 &gt; 0);</P>
<P>&nbsp; if FCode then<BR>&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp; for n := 1 to 16 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for h := 1 to 48 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; G[n, h] := C[Sc[n, h]];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;<BR>&nbsp;&nbsp;&nbsp; end<BR>&nbsp; else<BR>&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp; for n := 1 to 16 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for h := 1 to 48 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; G[17 - n, h] := C[Sc[n, h]];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;<BR>&nbsp;&nbsp;&nbsp; end;<BR>end;</P>
<P>procedure DES_Code(Input: TBlock; var Output: TBlock);<BR>var<BR>&nbsp; n: Byte;<BR>&nbsp; z: Word;<BR>begin<BR>&nbsp; L[1]&nbsp; := Ord(Input[7] and 64 &gt; 0); R[1]&nbsp; := Ord(Input[7] and 128 &gt; 0);<BR>&nbsp; L[2]&nbsp; := Ord(Input[6] and 64 &gt; 0); R[2]&nbsp; := Ord(Input[6] and 128 &gt; 0);<BR>&nbsp; L[3]&nbsp; := Ord(Input[5] and 64 &gt; 0); R[3]&nbsp; := Ord(Input[5] and 128 &gt; 0);<BR>&nbsp; L[4]&nbsp; := Ord(Input[4] and 64 &gt; 0); R[4]&nbsp; := Ord(Input[4] and 128 &gt; 0);<BR>&nbsp; L[5]&nbsp; := Ord(Input[3] and 64 &gt; 0); R[5]&nbsp; := Ord(Input[3] and 128 &gt; 0);<BR>&nbsp; L[6]&nbsp; := Ord(Input[2] and 64 &gt; 0); R[6]&nbsp; := Ord(Input[2] and 128 &gt; 0);<BR>&nbsp; L[7]&nbsp; := Ord(Input[1] and 64 &gt; 0); R[7]&nbsp; := Ord(Input[1] and 128 &gt; 0);<BR>&nbsp; L[8]&nbsp; := Ord(Input[0] and 64 &gt; 0); R[8]&nbsp; := Ord(Input[0] and 128 &gt; 0);<BR>&nbsp; L[9]&nbsp; := Ord(Input[7] and 16 &gt; 0); R[9]&nbsp; := Ord(Input[7] and 32 &gt; 0);<BR>&nbsp; L[10] := Ord(Input[6] and 16 &gt; 0); R[10] := Ord(Input[6] and 32 &gt; 0);<BR>&nbsp; L[11] := Ord(Input[5] and 16 &gt; 0); R[11] := Ord(Input[5] and 32 &gt; 0);<BR>&nbsp; L[12] := Ord(Input[4] and 16 &gt; 0); R[12] := Ord(Input[4] and 32 &gt; 0);<BR>&nbsp; L[13] := Ord(Input[3] and 16 &gt; 0); R[13] := Ord(Input[3] and 32 &gt; 0);<BR>&nbsp; L[14] := Ord(Input[2] and 16 &gt; 0); R[14] := Ord(Input[2] and 32 &gt; 0);<BR>&nbsp; L[15] := Ord(Input[1] and 16 &gt; 0); R[15] := Ord(Input[1] and 32 &gt; 0);<BR>&nbsp; L[16] := Ord(Input[0] and 16 &gt; 0); R[16] := Ord(Input[0] and 32 &gt; 0);<BR>&nbsp; L[17] := Ord(Input[7] and 4 &gt; 0);&nbsp; R[17] := Ord(Input[7] and 8 &gt; 0);<BR>&nbsp; L[18] := Ord(Input[6] and 4 &gt; 0);&nbsp; R[18] := Ord(Input[6] and 8 &gt; 0);<BR>&nbsp; L[19] := Ord(Input[5] and 4 &gt; 0);&nbsp; R[19] := Ord(Input[5] and 8 &gt; 0);<BR>&nbsp; L[20] := Ord(Input[4] and 4 &gt; 0);&nbsp; R[20] := Ord(Input[4] and 8 &gt; 0);<BR>&nbsp; L[21] := Ord(Input[3] and 4 &gt; 0);&nbsp; R[21] := Ord(Input[3] and 8 &gt; 0);<BR>&nbsp; L[22] := Ord(Input[2] and 4 &gt; 0);&nbsp; R[22] := Ord(Input[2] and 8 &gt; 0);<BR>&nbsp; L[23] := Ord(Input[1] and 4 &gt; 0);&nbsp; R[23] := Ord(Input[1] and 8 &gt; 0);<BR>&nbsp; L[24] := Ord(Input[0] and 4 &gt; 0);&nbsp; R[24] := Ord(Input[0] and 8 &gt; 0);<BR>&nbsp; L[25] := Input[7] and 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R[25] := Ord(Input[7] and 2 &gt; 0);<BR>&nbsp; L[26] := Input[6] and 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R[26] := Ord(Input[6] and 2 &gt; 0);<BR>&nbsp; L[27] := Input[5] and 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R[27] := Ord(Input[5] and 2 &gt; 0);<BR>&nbsp; L[28] := Input[4] and 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R[28] := Ord(Input[4] and 2 &gt; 0);<BR>&nbsp; L[29] := Input[3] and 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R[29] := Ord(Input[3] and 2 &gt; 0);<BR>&nbsp; L[30] := Input[2] and 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R[30] := Ord(Input[2] and 2 &gt; 0);<BR>&nbsp; L[31] := Input[1] and 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R[31] := Ord(Input[1] and 2 &gt; 0);<BR>&nbsp; L[32] := Input[0] and 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R[32] := Ord(Input[0] and 2 &gt; 0);</P>
<P>&nbsp; for n := 1 to 16 do<BR>&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp; z := ((R[32] xor G[n, 1]) shl 5) or ((R[5] xor G[n, 6]) shl 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[ 1] xor G[n, 2]) shl 3) or ((R[2] xor G[n, 3]) shl 2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[ 3] xor G[n, 4]) shl 1) or ( R[4] xor G[n, 5]);<BR>&nbsp;&nbsp;&nbsp; F[ 9] := L[ 9] xor SA1[z];<BR>&nbsp;&nbsp;&nbsp; F[17] := L[17] xor SB1[z];<BR>&nbsp;&nbsp;&nbsp; F[23] := L[23] xor SC1[z];<BR>&nbsp;&nbsp;&nbsp; F[31] := L[31] xor SD1[z];</P>
<P>&nbsp;&nbsp;&nbsp; z := ((R[4] xor G[n,&nbsp; 7]) shl 5) or ((R[9] xor G[n, 12]) shl 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[5] xor G[n,&nbsp; 8]) shl 3) or ((R[6] xor G[n,&nbsp; 9]) shl 2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[7] xor G[n, 10]) shl 1) or ( R[8] xor G[n, 11]);<BR>&nbsp;&nbsp;&nbsp; F[13] := L[13] xor SA2[z];<BR>&nbsp;&nbsp;&nbsp; F[28] := L[28] xor SB2[z];<BR>&nbsp;&nbsp;&nbsp; F[ 2] := L[ 2] xor SC2[z];<BR>&nbsp;&nbsp;&nbsp; F[18] := L[18] xor SD2[z];</P>
<P>&nbsp;&nbsp;&nbsp; z := ((R[ 8] xor G[n, 13]) shl 5) or ((R[13] xor G[n, 18]) shl 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[ 9] xor G[n, 14]) shl 3) or ((R[10] xor G[n, 15]) shl 2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[11] xor G[n, 16]) shl 1) or ( R[12] xor G[n, 17]);<BR>&nbsp;&nbsp;&nbsp; F[24] := L[24] xor SA3[z];<BR>&nbsp;&nbsp;&nbsp; F[16] := L[16] xor SB3[z];<BR>&nbsp;&nbsp;&nbsp; F[30] := L[30] xor SC3[z];<BR>&nbsp;&nbsp;&nbsp; F[ 6] := L[ 6] xor SD3[z];</P>
<P>&nbsp;&nbsp;&nbsp; z := ((R[12] xor G[n, 19]) shl 5) or ((R[17] xor G[n, 24]) shl 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[13] xor G[n, 20]) shl 3) or ((R[14] xor G[n, 21]) shl 2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[15] xor G[n, 22]) shl 1) or ( R[16] xor G[n, 23]);<BR>&nbsp;&nbsp;&nbsp; F[26] := L[26] xor SA4[z];<BR>&nbsp;&nbsp;&nbsp; F[20] := L[20] xor SB4[z];<BR>&nbsp;&nbsp;&nbsp; F[10] := L[10] xor SC4[z];<BR>&nbsp;&nbsp;&nbsp; F[ 1] := L[ 1] xor SD4[z];</P>
<P>&nbsp;&nbsp;&nbsp; z := ((R[16] xor G[n, 25]) shl 5) or ((R[21] xor G[n, 30]) shl 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[17] xor G[n, 26]) shl 3) or ((R[18] xor G[n, 27]) shl 2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[19] xor G[n, 28]) shl 1) or ( R[20] xor G[n, 29]);<BR>&nbsp;&nbsp;&nbsp; F[ 8] := L[ 8] xor SA5[z];<BR>&nbsp;&nbsp;&nbsp; F[14] := L[14] xor SB5[z];<BR>&nbsp;&nbsp;&nbsp; F[25] := L[25] xor SC5[z];<BR>&nbsp;&nbsp;&nbsp; F[ 3] := L[ 3] xor SD5[z];</P>
<P>&nbsp;&nbsp;&nbsp; z := ((R[20] xor G[n, 31]) shl 5) or ((R[25] xor G[n, 36]) shl 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[21] xor G[n, 32]) shl 3) or ((R[22] xor G[n, 33]) shl 2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[23] xor G[n, 34]) shl 1) or ( R[24] xor G[n, 35]);<BR>&nbsp;&nbsp;&nbsp; F[ 4] := L[ 4] xor SA6[z];<BR>&nbsp;&nbsp;&nbsp; F[29] := L[29] xor SB6[z];<BR>&nbsp;&nbsp;&nbsp; F[11] := L[11] xor SC6[z];<BR>&nbsp;&nbsp;&nbsp; F[19] := L[19] xor SD6[z];</P>
<P>&nbsp;&nbsp;&nbsp; z := ((R[24] xor G[n, 37]) shl 5) or ((R[29] xor G[n, 42]) shl 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[25] xor G[n, 38]) shl 3) or ((R[26] xor G[n, 39]) shl 2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[27] xor G[n, 40]) shl 1) or ( R[28] xor G[n, 41]);<BR>&nbsp;&nbsp;&nbsp; F[32] := L[32] xor SA7[z];<BR>&nbsp;&nbsp;&nbsp; F[12] := L[12] xor SB7[z];<BR>&nbsp;&nbsp;&nbsp; F[22] := L[22] xor SC7[z];<BR>&nbsp;&nbsp;&nbsp; F[ 7] := L[ 7] xor SD7[z];</P>
<P>&nbsp;&nbsp;&nbsp; z := ((R[28] xor G[n, 43]) shl 5) or ((R[ 1] xor G[n, 48]) shl 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[29] xor G[n, 44]) shl 3) or ((R[30] xor G[n, 45]) shl 2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ((R[31] xor G[n, 46]) shl 1) or ( R[32] xor G[n, 47]);<BR>&nbsp;&nbsp;&nbsp; F[ 5] := L[ 5] xor SA8[z];<BR>&nbsp;&nbsp;&nbsp; F[27] := L[27] xor SB8[z];<BR>&nbsp;&nbsp;&nbsp; F[15] := L[15] xor SC8[z];<BR>&nbsp;&nbsp;&nbsp; F[21] := L[21] xor SD8[z];</P>
<P>&nbsp;&nbsp;&nbsp; L := R;<BR>&nbsp;&nbsp;&nbsp; R := F;<BR>&nbsp;&nbsp;&nbsp; end;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp; Output[0] := (L[8] shl 7) or (R[8] shl 6) or (L[16] shl 5) or (R[16] shl 4)<BR>&nbsp;&nbsp;&nbsp; or (L[24] shl 3) or (R[24] shl 2) or (L[32] shl 1) or R[32];<BR>&nbsp; Output[1] := (L[7] shl 7) or (R[7] shl 6) or (L[15] shl 5) or (R[15] shl 4)<BR>&nbsp;&nbsp;&nbsp; or (L[23] shl 3) or (R[23] shl 2) or (L[31] shl 1) or R[31];<BR>&nbsp; Output[2] := (L[6] shl 7) or (R[6] shl 6) or (L[14] shl 5) or (R[14] shl 4)<BR>&nbsp;&nbsp;&nbsp; or (L[22] shl 3) or (R[22] shl 2) or (L[30] shl 1) or R[30];<BR>&nbsp; Output[3] := (L[5] shl 7) or (R[5] shl 6) or (L[13] shl 5) or (R[13] shl 4)<BR>&nbsp;&nbsp;&nbsp; or (L[21] shl 3) or (R[21] shl 2) or (L[29] shl 1) or R[29];<BR>&nbsp; Output[4] := (L[4] shl 7) or (R[4] shl 6) or (L[12] shl 5) or (R[12] shl 4)<BR>&nbsp;&nbsp;&nbsp; or (L[20] shl 3) or (R[20] shl 2) or (L[28] shl 1) or R[28];<BR>&nbsp; Output[5] := (L[3] shl 7) or (R[3] shl 6) or (L[11] shl 5) or (R[11] shl 4)<BR>&nbsp;&nbsp;&nbsp; or (L[19] shl 3) or (R[19] shl 2) or (L[27] shl 1) or R[27];<BR>&nbsp; Output[6] := (L[2] shl 7) or (R[2] shl 6) or (L[10] shl 5) or (R[10] shl 4)<BR>&nbsp;&nbsp;&nbsp; or (L[18] shl 3) or (R[18] shl 2) or (L[26] shl 1) or R[26];<BR>&nbsp; Output[7] := (L[1] shl 7) or (R[1] shl 6) or (L[9] shl 5) or (R[9] shl 4)<BR>&nbsp;&nbsp;&nbsp; or (L[17] shl 3) or (R[17] shl 2) or (L[25] shl 1) or R[25];<BR>end;</P>
<P>function StrToKey(aKey: string): TBlock;<BR>var<BR>&nbsp; Key : TBlock;<BR>&nbsp; I&nbsp;&nbsp; : Integer;<BR>begin<BR>&nbsp; FillChar(Key, SizeOf(TBlock), 0);<BR>&nbsp; for I := 1 to Length(aKey) do<BR>&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp; Key[I mod SizeOf(TBlock)] := Key[I mod SizeOf(TBlock)] + Ord(aKey[I]);<BR>&nbsp;&nbsp;&nbsp; end;</P>
<P>&nbsp; result := Key;<BR>end;</P>
<P>function EnCrypt(aStr: string; acKey: string ): string;<BR>var<BR>&nbsp; ReadBuf : TBlock;<BR>&nbsp; WriteBuf: TBlock;<BR>&nbsp; Key&nbsp;&nbsp;&nbsp;&nbsp; : TBlock;<BR>&nbsp; Count&nbsp;&nbsp; : Integer;<BR>&nbsp; Offset&nbsp; : Integer;</P>
<P>&nbsp; I&nbsp;&nbsp; : Integer;<BR>&nbsp; S&nbsp;&nbsp; : string;<BR>begin<BR>&nbsp; result := '';</P>
<P>&nbsp; Key := StrToKey(acKey);<BR>&nbsp; Des_Init(Key, True);</P>
<P>&nbsp; Offset := 1;<BR>&nbsp; Count&nbsp; := Length(aStr);<BR>&nbsp; repeat<BR>&nbsp;&nbsp;&nbsp; S := Copy(aStr, Offset, 8);<BR>&nbsp;&nbsp;&nbsp; FillChar(ReadBuf, 8, 0);<BR>&nbsp;&nbsp;&nbsp; Move(S[1], ReadBuf, Length(S));<BR>&nbsp;&nbsp;&nbsp; Des_Code(ReadBuf, WriteBuf);</P>
<P>&nbsp;&nbsp;&nbsp; for I := 0 to 7 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result := result + IntToHex(WriteBuf[I], 2);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;</P>
<P>&nbsp;&nbsp;&nbsp; Offset := Offset + 8;<BR>&nbsp; until Offset &gt; ((Count+7) div 8) * 8;<BR>end;</P>
<P>function DeCrypt(aStr: string; acKey: string ): string;<BR>var<BR>&nbsp; ReadBuf,<BR>&nbsp; WriteBuf : TBlock;<BR>&nbsp; Key&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : TBlock;<BR>&nbsp; Offset&nbsp; : Integer;<BR>&nbsp; Count&nbsp;&nbsp; : Integer;<BR>&nbsp; I&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Integer;<BR>&nbsp; S&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : string;<BR>begin<BR>&nbsp; try<BR>&nbsp;&nbsp;&nbsp; Key := StrToKey(acKey);<BR>&nbsp;&nbsp;&nbsp; Des_Init(Key, False);<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; S := '';<BR>&nbsp;&nbsp;&nbsp; I := 1;<BR>&nbsp;&nbsp;&nbsp; repeat<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S := S + Chr(StrToInt('$'+Copy(aStr, I, 2)));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Inc(I, 2);<BR>&nbsp;&nbsp;&nbsp; until I &gt; Length(aStr);</P>
<P>&nbsp;&nbsp;&nbsp; Offset := 1;<BR>&nbsp;&nbsp;&nbsp; Count&nbsp; := Length(S);<BR>&nbsp;&nbsp;&nbsp; while Offset &lt; ((Count+7) div 8 * 8) do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FillChar(ReadBuf, 8, 0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Move(S[Offset], ReadBuf, 8);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Des_Code(ReadBuf, WriteBuf);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for I := 0 to 7 do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result := result + Chr(WriteBuf[I]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Offset := Offset + 8;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;</P>
<P>&nbsp;&nbsp;&nbsp; result := StrPas(PChar(result));<BR>&nbsp; except<BR>&nbsp;&nbsp;&nbsp; result := '';<BR>&nbsp; end;<BR>end;</P>
<P>end.</P>
<P>&nbsp;</P></SPAN><img src ="http://www.blogjava.net/sunlea/aggbug/6869.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sunlea/" target="_blank">Sunlea 的空间</a> 2005-06-29 12:46 <a href="http://www.blogjava.net/sunlea/articles/6869.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>