希望大家帮帮我啊。//加密程序
function Encrypt(const S: String; Key: Word): String;
var
  I: byte;
  c1:Integer;
  c2:integer;
begin
  C1 := 52845;
  C2 := 22719;
  SetLength(Result,Length(S));
  for I := 1 to Length(S) do begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
    Key       := (byte(Result[I]) + Key) * C1 + C2;
  end;
end;//解密程序
function Decrypt(const S: String; Key: Word): String;
var
  I: byte;
  c1:Integer;
  c2:integer;
begin
  C1 := 52845;
  C2 := 22719;
  SetLength(Result,Length(S));
  for I := 1 to Length(S) do begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
    Key := (byte(S[I]) + Key) * C1 + C2;
  end;
end;

解决方案 »

  1.   

    你该不是,两次使用的key不一样吧?
      

  2.   

    上面这位朋友说得对他的KEY是两个不同的了
    不要设为全局变量只是好象这样不对哦,
      

  3.   

    用用我的函数,加\解密为同一个(key=1时为加密,0为解密)function Decrypt(const S:string;key:integer):string;
    function TForm1.Decrypt(const S:string;key:integer):string;
    var
       I:Integer;
    begin
       Result:='';
       case key of
       1:  //加密
        begin
          for i:=1 to length(s) do
             result := result+chr(ord(s[i]) xor i xor 69);
          result := result + char(69);
        end;
       0:  //解密
        begin
          for i:=1 to length(s) - 1 do
             result := result+chr(ord(s[i]) xor i xor 69);
        end;
       end;
    end;
      

  4.   

    你可能是两次使用的key不一样吧?
      

  5.   

    变参!!!
    我想key的值要传出来的,也就是说"var key:word"