飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 4473|回复: 17

第一个delphi程序,请指点

[复制链接]

该用户从未签到

发表于 2007-12-5 13:03:59 | 显示全部楼层 |阅读模式
  1. unit Unit1;

  2. interface

  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, jpeg, ExtCtrls;

  6. type
  7.   TForm1 = class(TForm)
  8.     Edit1: TEdit;
  9.     Edit2: TEdit;
  10.     Button1: TButton;
  11.     Image1: TImage;
  12.     Label1: TLabel;
  13.     Label2: TLabel;
  14.     procedure Button1Click(Sender: TObject);

  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;

  20. type LongWordArray =array of LongWord;
  21. type PArrayByte =array of Byte;

  22. var
  23.   Form1: TForm1;

  24. implementation

  25. {$R *.dfm}


  26. function md5_f ( x, y, z : LongWord ) : LongWord ;
  27. begin
  28.   Result := ( ( x and y) or ( ( not x) and z ) );
  29. end;


  30. function md5_g ( x, y, z : LongWord ) : LongWord ;
  31. begin
  32.   Result := ( ( x and z) or ( ( not z) and y ) );
  33. end;


  34. function md5_h ( x, y, z : LongWord ) : LongWord ;
  35. begin
  36.   Result := (  x xor y xor z );
  37. end;


  38. function md5_i ( x, y, z : LongWord ) : LongWord ;
  39. begin
  40.   Result := (  y xor (x or (not z)));
  41. end;


  42. function md5_RotateLeft ( x, s: LongWord ) : LongWord ;
  43. begin
  44.   Result := ( (x shl s) or (x shr (32- s)));
  45. end;


  46. procedure md5_ff ( var a:LongWord ;b,c,d,mj,s,ti :LongWord );
  47. begin
  48.   a:=a+ md5_f(b,c,d)+mj+ti;
  49.   a:=md5_RotateLeft(a,s);
  50.   a:=a+b;
  51. end;


  52. procedure md5_gg ( var a:LongWord ;b,c,d,mj,s,ti :LongWord );
  53. begin
  54.   a:=a+ md5_g(b,c,d)+mj+ti;
  55.   a:=md5_RotateLeft(a,s);
  56.   a:=a+b;
  57. end;


  58. procedure md5_hh ( var a:LongWord ;b,c,d,mj,s,ti :LongWord );
  59. begin
  60.   a:=a+ md5_h(b,c,d)+mj+ti;
  61.   a:=md5_RotateLeft(a,s);
  62.   a:=a+b;
  63. end;


  64. procedure md5_ii ( var a:LongWord ;b,c,d,mj,s,ti :LongWord );
  65. begin
  66.   a:=a+ md5_i(b,c,d)+mj+ti;
  67.   a:=md5_RotateLeft(a,s);
  68.   a:=a+b;
  69. end;


  70. procedure md5_MakeOneTurn ( var a,b,c,d:LongWord ; messageGroup:LongWordArray);
  71. begin
  72.         md5_ff(a, b, c, d, messageGroup[ 0],  7, $d76aa478);
  73.         md5_ff(d, a, b, c, messageGroup[ 1], 12, $e8c7b756);
  74.         md5_ff(c, d, a, b, messageGroup[ 2], 17, $242070db);
  75.         md5_ff(b, c, d, a, messageGroup[ 3], 22, $c1bdceee);
  76.         md5_ff(a, b, c, d, messageGroup[ 4],  7, $f57c0faf);
  77.         md5_ff(d, a, b, c, messageGroup[ 5], 12, $4787c62a);
  78.         md5_ff(c, d, a, b, messageGroup[ 6], 17, $a8304613);
  79.         md5_ff(b, c, d, a, messageGroup[ 7], 22, $fd469501);
  80.         md5_ff(a, b, c, d, messageGroup[ 8],  7, $698098d8);
  81.         md5_ff(d, a, b, c, messageGroup[ 9], 12, $8b44f7af);
  82.         md5_ff(c, d, a, b, messageGroup[10], 17, $ffff5bb1);
  83.         md5_ff(b, c, d, a, messageGroup[11], 22, $895cd7be);
  84.         md5_ff(a, b, c, d, messageGroup[12],  7, $6b901122);
  85.         md5_ff(d, a, b, c, messageGroup[13], 12, $fd987193);
  86.         md5_ff(c, d, a, b, messageGroup[14], 17, $a679438e);
  87.         md5_ff(b, c, d, a, messageGroup[15], 22, $49b40821);

  88.         md5_gg(a, b, c, d, messageGroup[ 1],  5, $f61e2562);
  89.         md5_gg(d, a, b, c, messageGroup[ 6],  9, $c040b340);
  90.         md5_gg(c, d, a, b, messageGroup[11], 14, $265e5a51);
  91.         md5_gg(b, c, d, a, messageGroup[ 0], 20, $e9b6c7aa);
  92.         md5_gg(a, b, c, d, messageGroup[ 5],  5, $d62f105d);
  93.         md5_gg(d, a, b, c, messageGroup[10],  9, $02441453);
  94.         md5_gg(c, d, a, b, messageGroup[15], 14, $d8a1e681);
  95.         md5_gg(b, c, d, a, messageGroup[ 4], 20, $e7d3fbc8);
  96.         md5_gg(a, b, c, d, messageGroup[ 9],  5, $21e1cde6);
  97.         md5_gg(d, a, b, c, messageGroup[14],  9, $c33707d6);
  98.         md5_gg(c, d, a, b, messageGroup[ 3], 14, $f4d50d87);
  99.         md5_gg(b, c, d, a, messageGroup[ 8], 20, $455a14ed);
  100.         md5_gg(a, b, c, d, messageGroup[13],  5, $a9e3e905);
  101.         md5_gg(d, a, b, c, messageGroup[ 2],  9, $fcefa3f8);
  102.         md5_gg(c, d, a, b, messageGroup[ 7], 14, $676f02d9);
  103.         md5_gg(b, c, d, a, messageGroup[12], 20, $8d2a4c8a);
  104.        
  105.         md5_hh(a, b, c, d, messageGroup[ 5],  4, $fffa3942);
  106.         md5_hh(d, a, b, c, messageGroup[ 8], 11, $8771f681);
  107.         md5_hh(c, d, a, b, messageGroup[11], 16, $6d9d6122);
  108.         md5_hh(b, c, d, a, messageGroup[14], 23, $fde5380c);
  109.         md5_hh(a, b, c, d, messageGroup[ 1],  4, $a4beea44);
  110.         md5_hh(d, a, b, c, messageGroup[ 4], 11, $4bdecfa9);
  111.         md5_hh(c, d, a, b, messageGroup[ 7], 16, $f6bb4b60);
  112.         md5_hh(b, c, d, a, messageGroup[10], 23, $bebfbc70);
  113.         md5_hh(a, b, c, d, messageGroup[13],  4, $289b7ec6);
  114.         md5_hh(d, a, b, c, messageGroup[ 0], 11, $eaa127fa);
  115.         md5_hh(c, d, a, b, messageGroup[ 3], 16, $d4ef3085);
  116.         md5_hh(b, c, d, a, messageGroup[ 6], 23, $04881d05);
  117.         md5_hh(a, b, c, d, messageGroup[ 9],  4, $d9d4d039);
  118.         md5_hh(d, a, b, c, messageGroup[12], 11, $e6db99e5);
  119.         md5_hh(c, d, a, b, messageGroup[15], 16, $1fa27cf8);
  120.         md5_hh(b, c, d, a, messageGroup[ 2], 23, $c4ac5665);
  121.        
  122.         md5_ii(a, b, c, d, messageGroup[ 0],  6, $f4292244);
  123.         md5_ii(d, a, b, c, messageGroup[ 7], 10, $432aff97);
  124.         md5_ii(c, d, a, b, messageGroup[14], 15, $ab9423a7);
  125.         md5_ii(b, c, d, a, messageGroup[ 5], 21, $fc93a039);
  126.         md5_ii(a, b, c, d, messageGroup[12],  6, $655b59c3);
  127.         md5_ii(d, a, b, c, messageGroup[ 3], 10, $8f0ccc92);
  128.         md5_ii(c, d, a, b, messageGroup[10], 15, $ffeff47d);
  129.         md5_ii(b, c, d, a, messageGroup[ 1], 21, $85845dd1);
  130.         md5_ii(a, b, c, d, messageGroup[ 8],  6, $6fa87e4f);
  131.         md5_ii(d, a, b, c, messageGroup[15], 10, $fe2ce6e0);
  132.         md5_ii(c, d, a, b, messageGroup[ 6], 15, $a3014314);
  133.         md5_ii(b, c, d, a, messageGroup[13], 21, $4e0811a1);
  134.         md5_ii(a, b, c, d, messageGroup[ 4],  6, $f7537e82);
  135.         md5_ii(d, a, b, c, messageGroup[11], 10, $bd3af235);
  136.         md5_ii(c, d, a, b, messageGroup[ 2], 15, $2ad7d2bb);
  137.         md5_ii(b, c, d, a, messageGroup[ 9], 21, $eb86d391);

  138. end;


  139. function md5_TurnType (PByte:PArrayByte):string;
  140. var
  141. i:LongWord;
  142. temp_num:Byte;
  143. temp: string ;
  144. begin

  145.    Result :='';

  146.    for i := 0 to 15 do
  147.    begin
  148.    temp_num :=pByte[i];
  149.    temp := Format('%02x',[temp_num]);
  150.    Result:=Result+temp;
  151.    end;

  152. end;


  153. function md5_Digest ( var message :string ;len : LongWord ) : string ;
  154. type
  155.   PointerToChar = ^char;
  156.   PointerToByte = ^Byte;

  157.   var

  158. thepointer,a,b,c,d,blen,groupLen,i:LongWord;
  159. save :array[1..4] of LongWord;
  160. Group :array[1..64] of char;
  161. p:array of char;
  162. pByte:PArrayByte;
  163. begin
  164.   save[1]:=$67452301;
  165.   save[2]:=$efcdab89;
  166.   save[3]:=$98badcfe;
  167.   save[4]:=$10325476;
  168.   i:=1;
  169.   thepointer:=0;

  170.   while thepointer <= len do
  171.   begin
  172.     groupLen := len - thepointer;
  173.                 if(groupLen > 64) then  groupLen := 64;

  174.                 for i := 1 to groupLen do
  175.       Group[i] := message[thepointer + i];

  176.     thepointer:=thepointer+groupLen;

  177.     if groupLen < 64 then
  178.     begin

  179.       if (groupLen > 0) or (len = 0)   then
  180.       begin
  181.       Group[i] := Chr($80);
  182.       i:=i+1;
  183.       end;

  184.       while i<=64 do
  185.       begin
  186.         Group[i] := chr(0);
  187.         i:=i+1;
  188.       end;

  189.       if groupLen < 56 then
  190.       begin
  191.         blen := len * 8;
  192.         //执行下面这句后save第4个元素不知道为什么加1了
  193.         p := @blen;
  194.         //搞不明白为什么会出现这种错误,,所以在这里-1,希望高手指点下
  195.         save[4]:=save[4]-1;
  196.         for i := 57 to 60 do
  197.           Group[i] := p[i - 57];

  198.         thepointer := len + 1;
  199.        end;
  200.     end;

  201.     a := save[1];
  202.     b := save[2];
  203.     c := save[3];
  204.     d := save[4];

  205.     md5_MakeOneTurn(a, b, c, d,@Group);
  206.     save[1] := save[1] +a;
  207.     save[2] := save[2] +b;
  208.     save[3] := save[3] +c;
  209.     save[4] := save[4] +d;

  210.    end;

  211.   Result:=md5_TurnType(@save);
  212. end;


  213. procedure TForm1.Button1Click(Sender: TObject);
  214. var
  215. text:string;
  216. len:LongWord;
  217. md5_text:string;
  218. begin
  219.   text:=Edit1.Text;
  220.   len :=Length(text);
  221.   md5_text:=md5_Digest(text,len);
  222.   Edit2.Text:=md5_text;

  223. end;

  224. end.
复制代码
上面代码有个地方有错,,注释有说明,希望会的指点下,,,

[ 本帖最后由 deletex 于 2007-12-22 17:55 编辑 ]

Project1.rar

247.04 KB, 下载次数: 26, 下载积分: 飘云币 -2 枚

PYG19周年生日快乐!
  • TA的每日心情
    开心
    2016-4-25 19:39
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    发表于 2007-12-5 19:36:51 | 显示全部楼层
    看不懂事什么意思?
    继续努力了!
    一起努力!
    PYG19周年生日快乐!
  • TA的每日心情
    慵懒
    2018-2-11 09:23
  • 签到天数: 8 天

    [LV.3]偶尔看看II

    发表于 2007-12-5 19:51:46 | 显示全部楼层
    第一个就搞这么多行干什么
    PYG19周年生日快乐!

    该用户从未签到

     楼主| 发表于 2007-12-5 20:07:18 | 显示全部楼层
    原帖由 冰糖 于 2007-12-5 19:51 发表
    第一个就搞这么多行干什么


    是从一个以前写的C++的程序改的,,:lol:
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2007-12-6 14:21:52 | 显示全部楼层
    好长啊!!!
    头都看大了!
    PYG19周年生日快乐!
  • TA的每日心情
    慵懒
    2019-2-17 18:27
  • 签到天数: 33 天

    [LV.5]常住居民I

    发表于 2007-12-10 17:21:51 | 显示全部楼层
    汗一个,看不懂
    PYG19周年生日快乐!
  • TA的每日心情

    2019-6-9 15:12
  • 签到天数: 35 天

    [LV.5]常住居民I

    发表于 2007-12-10 20:34:31 | 显示全部楼层
    我是小菜,看不懂,先学习。。。。。/:014
    PYG19周年生日快乐!
  • TA的每日心情
    无聊
    2019-3-25 06:30
  • 签到天数: 1096 天

    [LV.10]以坛为家III

    发表于 2007-12-10 21:47:59 | 显示全部楼层
    没看懂,看大家怎么弄
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2007-12-22 18:14:14 | 显示全部楼层
    看不懂,好像已超出了讲课范围!!
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2007-12-23 20:28:59 | 显示全部楼层
    看不懂 啊!加紧学
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表