interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    btn1: TButton;
    edt1: TEdit;
    edt2: TEdit;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
type
  PArrayByte=^TArrayByte;
  TArrayByte=array of Byte;
var
  Form1: TForm1;implementation{$R *.dfm}
function MyRC4(Byuanwen:array of Byte ;key:string):pArrayByte;  //我的RC4加解密程序
var
  m,k:array [0..255] of Byte ;
  x,j,i,LMima,LYuanwen :Integer ;
  OutDate:pArrayByte;
  temp:Byte;
  Bkey:array of Byte ;
begin
  for i:=0 to 255 do
  begin
     m[i]:=i;
  end;
  LMima := Length (key);
  if LMima >0 then
  begin
    SetLength (Bkey,LMima);
    CopyMemory(@Bkey[0],PChar(key),LMima);
    j:=0;
    for i:=0 to 255 do
    begin
      k[i]:=bkey[j];
      j:=j+1;
      if j > LMima -1 then j:=0;
    end;
    j:=0;
    for i:=0 to 255 do
    begin
       j := (j+m[i]+k[i])and 255;
       temp := m [i];
       m [i] := m [j];
       m [j] := temp;
    end;
  end;
  i:=0;
  j:=0;
  LYuanwen :=Length (Byuanwen);
  //GetMem (outdate,SizeOf (OutDate)*20);
  SetLength (OutDate^,LYuanwen);
  for x:=0 to LYuanwen do
  begin
    i:= (i+1) and 255;
    j:= (j+m[i]) and 255;
    temp := m[i];
    m[i] :=m[j];
    m[j]:=temp;
    OutDate^[x]:= Byuanwen[x] xor m[((m[i]+m[j]) and 255)];
  end;
  Result := OutDate;
  //OutDate :=nil;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
  s:string;
  i,l:Integer;
  Byuanwen,t:TArrayByte;
  p:parraybyte;
begin
getDir(0,s);
edt1.Text := s;
l:=Length (s);
SetLength (byuanwen,l);
CopyMemory(@byuanwen[0],PChar(s),l);
New(p);
p:= MyRC4(byuanwen,'123456');
SetLength (t,High (p^));
t:=p^;
dispose(p);
New(p);
p:= MyRC4(t,'123456');
t:=nil;
SetLength (t,High (p^));
t:=p^;
dispose(p);
s:='';
for i:=0 to High (t) do
begin
  if s='' then s:= inttostr(t[i])
  else s:=s+','+inttostr(t[i])
end;
edt2.Text :=s;
end;end.

解决方案 »

  1.   

    程序编译后只能在D:\Program Files\Borland\Delphi7\Projects目录下运行
      

  2.   

    感觉你的代码第一命名很不规范,第二格式没有什么缩进,看起来很不清晰.第三,对new和dispose操作最好加上try..finally
    另外感觉你的PArrayByte=^TArrayByte; 定义的有点别扭,数组本身就是一个指到数组第一个元素的指针,那你直接用pointer指到第一个元素就可以了。
    其他的没怎么看.