对一串字符串进行加密可以用到哪些函数,
有实例最好

解决方案 »

  1.   

    Function Encrypt(str:string;bEncry:Boolean):string;
    var
       I: byte;
       ftem:string;
    begin
       if str='' then
       begin
          result:='';
          exit;
       end;
       ftem:=str;
       if bEncry then
       begin
          for I := 1 to Length(Str) do
          begin
            if byte(Str[I]) <= 50 then
              ftem[I] := char( byte(Str[I]) - 10 )
            else if (byte(Str[I]) > 50) and (byte(Str[I]) <= 90) then
              ftem[I] := char( byte(Str[I]) + 30 )
            else if (byte(Str[I]) > 90) and (byte(Str[I]) <= 128) then
              ftem[I] := char( byte(Str[I]) - 50 )
            else if (byte(Str[I]) > 128) then
              ftem[I] := char( byte(Str[I]) - 6 );
          end;
       end
       else
       begin
          for I := 1 to Length(Str) do
          begin
            if byte(Str[I]) <= 40 then
              ftem[I] := char( byte(Str[I]) + 10 )
            else if (byte(Str[I]) > 40) and (byte(Str[I]) <= 80) then
              ftem[I] := char( byte(Str[I]) + 50 )
            else if (byte(Str[I]) > 80) and (byte(Str[I]) <= 120) then
              ftem[I] := char( byte(Str[I]) - 30 )
            else if (byte(Str[I]) > 120) then
              ftem[I] := char( byte(Str[I]) + 6 );
          end;
       end;
       result:=ftem;
    end;
      

  2.   

    function codechange(s:string;num:integer):string;
    var
      i:integer;
      temp:array[0..100] of char;
      outstring:string;
    begin
    if length(s)>100 then
       begin
       application.MessageBox('要转换的字符太大,无法转换','错误',48);
       result:=s;
       exit
       end;
    strpcopy(temp,s);
    for i:=0 to length(s)-1 do
        outstring:=outstring+chr(ord(temp[i])+num);
    result:=outstring;
    end;s:表示要加密的字符,num:表示要加密的ASC码相对值增加多少
    例如
    假设 A:='a'
    对 A进行加密
    B:=codechange(A,1)
    对 A进行解密
    A:=codechange(B,-1)
    注意后面的num值
    num值可以自己定,加密解密是相反的数字
    我自己搞的函数,你用用看