我想把一个字符串加密
让别人不能显示的看到他是什么,但要能够恢复出来

解决方案 »

  1.   

    你到书店买本电脑报出的DELPHI6的一本编程技巧和实例带两张光盘上边有现成的东西28元
      

  2.   

    SeedA             = 78;   /// 字符加密常量
      SeedB             = 32;   /// 字符加密常量function TSYSMAIN.Crypt(const s: String; Key: Word; const bEncrypt: boolean = True): String;
    var            //字符串加解密
      i       : integer;
      ps, pr  : ^byte;
    begin
      SetLength(Result, Length(s));
      ps := @s[1];
      pr := @Result[1];
      for i := 1 to length(s) do
      begin
        pr^ := ps^ xor (Key shr 8);
        if bEncrypt then
          Key := (pr^ + Key) * SeedA + SeedB
        else
          Key := (ps^ + Key) * SeedA + SeedB;
        pr := pointer(integer(pr) + 1);
        ps := pointer(integer(ps) + 1);
      end
    end;
      

  3.   

    Function encrypt_str(sourec_str:String):String;
    //加密字符串数据
    var
      the_length:Integer;
    begin
      For the_length:=1 to length(sourec_str) do
      begin
        if (ord(sourec_str[the_length])>=58) and (ord(sourec_str[the_length])<=122) then
          result:=result+chr(ord(sourec_str[the_length])-10)
        else
          if (ord(sourec_str[the_length])>=48) and (ord(sourec_str[the_length])<=57) then
            result:=result+chr(ord(sourec_str[the_length])-20)
          else
            result:=result+sourec_str[the_length];
      end;
    end;Function unencrypt_str(sourec_str:String):String;
    //解密字符串
    var
      the_length:Integer;
    begin
      For the_length:=1 to length(sourec_str) do
      begin
        if (ord(sourec_str[the_length])>=28) and (ord(sourec_str[the_length])<=37) then
          result:=result+chr(ord(sourec_str[the_length])+20)
        else
          if (ord(sourec_str[the_length])>=48) and (ord(sourec_str[the_length])<=112) then
            result:=result+chr(ord(sourec_str[the_length])+10)
          else
            result:=result+sourec_str[the_length];
      end;
    end;
      

  4.   

    function Encrypt(const S: String; Key: Word): String;
    var
       I: 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;
    end;function Decrypt(const S: String; Key: Word): String;
    var
       I: Integer;
    begin
      Result := 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;