要规范啊!!
利于菜鸟偶学习~~/:001 我跟了一下汇编,也综合考虑了一下。修改了一下程序 供你参考
具体为什么会引起这个问题,个人认为是动态数组定义哪里造成的
修改代码如下: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
SetLength(save,5);
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. 没看懂,看大家le p的类型为:array of char
blen的类型为LongWord;
p:=@bLen; 该指令是将bLen的地址赋值给p;bLen为临时变量,存储在栈中.
这条指令执行后,程序执行了一些附加代码,这些代码将使得p地址pAddr之前的单元pAddr-8的内容加1,
而pAddr-8刚好是Save的地址(pAddr-4为Group的地址); 没看懂是干什么用的,要加紧学拉,努力中。。。。 代码实在太强大了!小人菜菜看不懂!/:002 /:002 /:002
页:
1
[2]