第一个delphi程序,请指点
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type LongWordArray =array of LongWord;
type PArrayByte =array of Byte;
var
Form1: TForm1;
implementation
{$R *.dfm}
function md5_f ( x, y, z : LongWord ) : LongWord ;
begin
Result := ( ( x and y) or ( ( not x) and z ) );
end;
function md5_g ( x, y, z : LongWord ) : LongWord ;
begin
Result := ( ( x and z) or ( ( not z) and y ) );
end;
function md5_h ( x, y, z : LongWord ) : LongWord ;
begin
Result := (x xor y xor z );
end;
function md5_i ( x, y, z : LongWord ) : LongWord ;
begin
Result := (y xor (x or (not z)));
end;
function md5_RotateLeft ( x, s: LongWord ) : LongWord ;
begin
Result := ( (x shl s) or (x shr (32- s)));
end;
procedure md5_ff ( var a:LongWord ;b,c,d,mj,s,ti :LongWord );
begin
a:=a+ md5_f(b,c,d)+mj+ti;
a:=md5_RotateLeft(a,s);
a:=a+b;
end;
procedure md5_gg ( var a:LongWord ;b,c,d,mj,s,ti :LongWord );
begin
a:=a+ md5_g(b,c,d)+mj+ti;
a:=md5_RotateLeft(a,s);
a:=a+b;
end;
procedure md5_hh ( var a:LongWord ;b,c,d,mj,s,ti :LongWord );
begin
a:=a+ md5_h(b,c,d)+mj+ti;
a:=md5_RotateLeft(a,s);
a:=a+b;
end;
procedure md5_ii ( var a:LongWord ;b,c,d,mj,s,ti :LongWord );
begin
a:=a+ md5_i(b,c,d)+mj+ti;
a:=md5_RotateLeft(a,s);
a:=a+b;
end;
procedure md5_MakeOneTurn ( var a,b,c,d:LongWord ; messageGroup:LongWordArray);
begin
md5_ff(a, b, c, d, messageGroup[ 0],7, $d76aa478);
md5_ff(d, a, b, c, messageGroup[ 1], 12, $e8c7b756);
md5_ff(c, d, a, b, messageGroup[ 2], 17, $242070db);
md5_ff(b, c, d, a, messageGroup[ 3], 22, $c1bdceee);
md5_ff(a, b, c, d, messageGroup[ 4],7, $f57c0faf);
md5_ff(d, a, b, c, messageGroup[ 5], 12, $4787c62a);
md5_ff(c, d, a, b, messageGroup[ 6], 17, $a8304613);
md5_ff(b, c, d, a, messageGroup[ 7], 22, $fd469501);
md5_ff(a, b, c, d, messageGroup[ 8],7, $698098d8);
md5_ff(d, a, b, c, messageGroup[ 9], 12, $8b44f7af);
md5_ff(c, d, a, b, messageGroup, 17, $ffff5bb1);
md5_ff(b, c, d, a, messageGroup, 22, $895cd7be);
md5_ff(a, b, c, d, messageGroup,7, $6b901122);
md5_ff(d, a, b, c, messageGroup, 12, $fd987193);
md5_ff(c, d, a, b, messageGroup, 17, $a679438e);
md5_ff(b, c, d, a, messageGroup, 22, $49b40821);
md5_gg(a, b, c, d, messageGroup[ 1],5, $f61e2562);
md5_gg(d, a, b, c, messageGroup[ 6],9, $c040b340);
md5_gg(c, d, a, b, messageGroup, 14, $265e5a51);
md5_gg(b, c, d, a, messageGroup[ 0], 20, $e9b6c7aa);
md5_gg(a, b, c, d, messageGroup[ 5],5, $d62f105d);
md5_gg(d, a, b, c, messageGroup,9, $02441453);
md5_gg(c, d, a, b, messageGroup, 14, $d8a1e681);
md5_gg(b, c, d, a, messageGroup[ 4], 20, $e7d3fbc8);
md5_gg(a, b, c, d, messageGroup[ 9],5, $21e1cde6);
md5_gg(d, a, b, c, messageGroup,9, $c33707d6);
md5_gg(c, d, a, b, messageGroup[ 3], 14, $f4d50d87);
md5_gg(b, c, d, a, messageGroup[ 8], 20, $455a14ed);
md5_gg(a, b, c, d, messageGroup,5, $a9e3e905);
md5_gg(d, a, b, c, messageGroup[ 2],9, $fcefa3f8);
md5_gg(c, d, a, b, messageGroup[ 7], 14, $676f02d9);
md5_gg(b, c, d, a, messageGroup, 20, $8d2a4c8a);
md5_hh(a, b, c, d, messageGroup[ 5],4, $fffa3942);
md5_hh(d, a, b, c, messageGroup[ 8], 11, $8771f681);
md5_hh(c, d, a, b, messageGroup, 16, $6d9d6122);
md5_hh(b, c, d, a, messageGroup, 23, $fde5380c);
md5_hh(a, b, c, d, messageGroup[ 1],4, $a4beea44);
md5_hh(d, a, b, c, messageGroup[ 4], 11, $4bdecfa9);
md5_hh(c, d, a, b, messageGroup[ 7], 16, $f6bb4b60);
md5_hh(b, c, d, a, messageGroup, 23, $bebfbc70);
md5_hh(a, b, c, d, messageGroup,4, $289b7ec6);
md5_hh(d, a, b, c, messageGroup[ 0], 11, $eaa127fa);
md5_hh(c, d, a, b, messageGroup[ 3], 16, $d4ef3085);
md5_hh(b, c, d, a, messageGroup[ 6], 23, $04881d05);
md5_hh(a, b, c, d, messageGroup[ 9],4, $d9d4d039);
md5_hh(d, a, b, c, messageGroup, 11, $e6db99e5);
md5_hh(c, d, a, b, messageGroup, 16, $1fa27cf8);
md5_hh(b, c, d, a, messageGroup[ 2], 23, $c4ac5665);
md5_ii(a, b, c, d, messageGroup[ 0],6, $f4292244);
md5_ii(d, a, b, c, messageGroup[ 7], 10, $432aff97);
md5_ii(c, d, a, b, messageGroup, 15, $ab9423a7);
md5_ii(b, c, d, a, messageGroup[ 5], 21, $fc93a039);
md5_ii(a, b, c, d, messageGroup,6, $655b59c3);
md5_ii(d, a, b, c, messageGroup[ 3], 10, $8f0ccc92);
md5_ii(c, d, a, b, messageGroup, 15, $ffeff47d);
md5_ii(b, c, d, a, messageGroup[ 1], 21, $85845dd1);
md5_ii(a, b, c, d, messageGroup[ 8],6, $6fa87e4f);
md5_ii(d, a, b, c, messageGroup, 10, $fe2ce6e0);
md5_ii(c, d, a, b, messageGroup[ 6], 15, $a3014314);
md5_ii(b, c, d, a, messageGroup, 21, $4e0811a1);
md5_ii(a, b, c, d, messageGroup[ 4],6, $f7537e82);
md5_ii(d, a, b, c, messageGroup, 10, $bd3af235);
md5_ii(c, d, a, b, messageGroup[ 2], 15, $2ad7d2bb);
md5_ii(b, c, d, a, messageGroup[ 9], 21, $eb86d391);
end;
function md5_TurnType (PByte:PArrayByte):string;
var
i:LongWord;
temp_num:Byte;
temp: string ;
begin
Result :='';
for i := 0 to 15 do
begin
temp_num :=pByte;
temp := Format('%02x',);
Result:=Result+temp;
end;
end;
function md5_Digest ( var message :string ;len : LongWord ) : string ;
type
PointerToChar = ^char;
PointerToByte = ^Byte;
var
thepointer,a,b,c,d,blen,groupLen,i:LongWord;
save :array of LongWord;
Group :array of char;
p:array of char;
pByte:PArrayByte;
begin
save:=$67452301;
save:=$efcdab89;
save:=$98badcfe;
save:=$10325476;
i:=1;
thepointer:=0;
while thepointer <= len do
begin
groupLen := len - thepointer;
if(groupLen > 64) thengroupLen := 64;
for i := 1 to groupLen do
Group := message;
thepointer:=thepointer+groupLen;
if groupLen < 64 then
begin
if (groupLen > 0) or (len = 0) then
begin
Group := Chr($80);
i:=i+1;
end;
while i<=64 do
begin
Group := chr(0);
i:=i+1;
end;
if groupLen < 56 then
begin
blen := len * 8;
//执行下面这句后save第4个元素不知道为什么加1了
p := @blen;
//搞不明白为什么会出现这种错误,,所以在这里-1,希望高手指点下
save:=save-1;
for i := 57 to 60 do
Group := p;
thepointer := len + 1;
end;
end;
a := save;
b := save;
c := save;
d := save;
md5_MakeOneTurn(a, b, c, d,@Group);
save := save +a;
save := save +b;
save := save +c;
save := save +d;
end;
Result:=md5_TurnType(@save);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
text:string;
len:LongWord;
md5_text:string;
begin
text:=Edit1.Text;
len :=Length(text);
md5_text:=md5_Digest(text,len);
Edit2.Text:=md5_text;
end;
end.上面代码有个地方有错,,注释有说明,希望会的指点下,,,
[ 本帖最后由 deletex 于 2007-12-22 17:55 编辑 ] 看不懂事什么意思?
继续努力了!
一起努力! 第一个就搞这么多行干什么 原帖由 冰糖 于 2007-12-5 19:51 发表 https://www.chinapyg.com/images/common/back.gif
第一个就搞这么多行干什么
是从一个以前写的C++的程序改的,,:lol: 好长啊!!!
头都看大了! 汗一个,看不懂 我是小菜,看不懂,先学习。。。。。/:014 没看懂,看大家怎么弄 看不懂,好像已超出了讲课范围!! 看不懂 啊!加紧学
页:
[1]
2