function SeqEnc(Str:String;Key:Integer;Times:Integer):string;
var
  i,c,n:Integer;  
  Key1,Key2,Key3,Key4:Byte;
begin
  n:=Length(Str);
  if n=0 then
    exit;
  Key4:=Byte(Key shr 24);
  Key3:=Byte(Key shr 16);
  Key2:=Byte(Key shr 8);
  Key1:=Byte(Key);   
  for c:=Times-1 downto 0 do
  begin
    Str[1]:=Char(Byte(Str[1])+Key3);
    for i:=2 to n do
      Str[i]:=Char((Byte(Str[i-1])+Byte(Str[i])) xor Key1);
    Str[n]:=Char(Byte(Str[n])+Key4);
    for i:=n-1 downto 1 do
      Str[i]:=Char((Byte(Str[i+1])+Byte(Str[i])) xor Key2);
  end;
  str:=strtohex(str);
  result:=str;
end;function SeqDec(Str:String;Key:Integer;Times:Integer):string;
var
  i,c,n:Integer;
  Key1,Key2,Key3,Key4:Byte;
begin
  str:=hextostr(str);
  n:=Length(Str);
  if n=0 then
    exit;
  Key4:=Byte(Key shr 24);
  Key3:=Byte(Key shr 16);
  Key2:=Byte(Key shr 8);
  Key1:=Byte(Key);         
  for c:=Times-1 downto 0 do
  begin
    for i:=1 to n-1 do
      Str[i]:=Char(Byte(Str[i]) xor Key2-Byte(Str[i+1]));
    Str[n]:=Char(Byte(Str[n])-Key4);
    for i:=n downto 2 do
      Str[i]:=Char(Byte(Str[i]) xor Key1-Byte(Str[i-1]));
    Str[1]:=Char(Byte(Str[1])-Key3);
  end;  result:=str;
end;