function Encrypt(S: string; Key: Word): string; //加密
function Decrypt(S: string; Key: Word): string; //解密
implementationfunction Encrypt(S: string; Key: Word): string;
var
  I: integer;
  J: integer;
begin
  Result := 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;
  S := Result;
  Result := '';
  for I := 1 to Length(S) do
  begin
    J := integer(S[I]);
    Result := Result + char(65 + (J div 26)) + char(65 + (J mod 26));
  end;
end;
function Decrypt(S: string; Key: Word): string;
var
  I: integer;
  J: integer;
begin
  Result := '';
  for I := 1 to (Length(S) div 2) do
  begin
    J := (integer(S[2 * I - 1]) - 65) * 26;
    J := J + (integer(S[2 * I]) - 65);
    Result := Result + char(J);
  end;
  S := Result;
  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;