Str1:='abc';
for i:=1 to Length(Str1) do
  Str1[i]:=Chr(Ord(Str1[i]) Xor 567);
//这里567就是密钥,再进行一下同样的操作就是解密。

解决方案 »

  1.   

    function EncryptString(sSrc, sKey: string): string;
    const
      sHex: array[0..15] of Char =
        ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
    var
      iKeyLen, iKeyPos, iOffset, iSrcPos, iSrcAsc: Integer;  function IntToHexStr(iNum: Integer): string;
      begin
        Result := sHex[iNum div 16] + sHex[iNum mod 16];
      end;begin
      if sSrc = '' then Exit;
      if sKey = '' then sKey := 'XZYLZH';
      iKeyLen := Length(sKey);
      iKeyPos := 0;  Randomize;
      iOffset := Random(256);
      Result := IntToHexStr(iOffset);
      for iSrcPos := 1 to Length(sSrc) do
      begin
        iSrcAsc := (Ord(sSrc[iSrcPos]) + iOffset) mod 255;
        if iKeyPos < iKeyLen then
          Inc(iKeyPos)
        else
          iKeyPos := 1;
        iSrcAsc := iSrcAsc xor Ord(sKey[iKeyPos]);
        Result := Result + IntToHexStr(iSrcAsc);
        iOffset := iSrcAsc;
      end;
    end;function DecryptString(sSrc, sKey: string): string;
    var
      iKeyLen, iKeyPos, iOffset, iSrcPos, iSrcAsc, iTmpSrcAsc: Integer;
    begin
      if sSrc = '' then Exit;
      if sKey = '' then sKey := 'XZYLZH';
      iKeyLen := Length(sKey);
      iKeyPos := 0;
      iOffset := StrToInt('$' + Copy(sSrc, 1, 2));
      iSrcPos := 3;
      repeat
        iSrcAsc := StrToInt('$' + Copy(sSrc, iSrcPos, 2));
        if iKeyPos < iKeyLen then
          Inc(iKeyPos, 1)
        else
          iKeyPos := 1;
        iTmpSrcAsc := iSrcAsc xor Ord(sKey[iKeyPos]);
        if iTmpSrcAsc <= iOffset then
          Inc(iTmpSrcAsc, 255 - iOffset)
        else
          Dec(iTmpSrcAsc, iOffset);
        Result := Result + Chr(iTmpSrcAsc);
        iOffset := iSrcAsc;
        Inc(iSrcPos, 2);
      until iSrcPos >= Length(sSrc);
    end;
      

  2.   

    可以用TurboPower控件组中的LockBox控件
    RSA、BLOWFISH等等加密方法都有
    很容易使用