最近上司让我作有一个加密的算法,我没做过所以请大侠们给点提示和建议
具体是这样的:
比如:ABCDJQBW12345678(16位),经过一个算法变成一串另外的数字和字母的密文
再通过一个算法把加密后的密文转换成上面16位的明文。要求算法比较复杂。请大侠帮帮忙。最好有加密和解密的源码。分数不够再加!!!谢谢!

解决方案 »

  1.   

    md5算法不错,但是单向的,也就是说把你的密码转成一个长串mi文,但无法转回来,用的时候也把输入的密码转一下与那个mi文对照,如要和我联系
      

  2.   

    VB脚本的,你自己改成Delphi的吧,应该不是很难写出解密函数
    =================================
    function encrypt( preString )
      Dim texts
      Dim seed
      Dim i,length
      prestring = trim(preString)
      length = len(preString)
      seed = length
      Randomize(length)
      texts = ""
      for i = 1 to length
        seed = int(94*rnd(-asc(mid(preString,i,1)) - seed*asc(right(prestring,1)))+32)
        texts = texts & chr(seed) & chr(int(94*rnd(-seed)+32))
      next
      dim dist
      dist = ""
      for i = 1 to len(texts)
        if mid(texts,i,1)<>"'" then
          dist=dist+mid(texts,i,1)
        end if
      next
      mistake = dist
    End function
      

  3.   

    function Crypt(s: string; Key: Word; const bEncrypt: boolean = True): string; //将字符串加密解密,bEncrypt=True表示加密,False表示解密
    const
      SeedA = 56789; /// 常量,你可以修改
      SeedB = 54329; /// 常量,你可以修改
    var
      i: integer;
      ps, pr : ^byte;
    begin
      if bEncrypt then
        s := s+#0;
      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;
      

  4.   

    有一个是des的,很不错,但是我在网上找不到,你可以找找,很多的
      

  5.   

    其实我要求的算法不需要太复杂,就像 ljmanage(过客)的就很不错!大家还有什么方法?
      

  6.   

    function jiami(str: string): string;
    var
      i,j:integer; //循环变量
      valuser:integer;
      tempuser:string;
      chageuser:string;
    //  biaozhi:boolean;
    begin
      try
      tempuser:=str;
      chageuser:='';
      for i:=1 to length(tempuser) do
      begin
        form1.biaozhi:=true;
        valuser := Ord(tempuser[i]);
        for j:=0 to 61 do
        begin
          if valuser=asci[j] then
          begin
            form1.biaozhi:=false;
            if j+2*i<=61 then
              valuser:=asci[j+2*i]
            else if i>30 then
            begin
              Application.MessageBox('用户名不能超过30位!','警告',mb_OK);
              exit;
            end
            else
              valuser:=asci[j+2*i-62];
            chageuser:=chageuser+chr(valuser);
            break;
          end;
        end;
        if form1.biaozhi then
        begin
          Application.MessageBox('用户名必须为数字或字母!','警告',mb_OK);
          result:=':)';
          exit;
        end;
      end;
      result:=chageuser;
      except
        Application.MessageBox('用户名加密失败,请重新登录系统!','错误',mb_OK);
      end;
    end;
    function jiemi(str: string): string;
    var
      i,j:integer; //循环变量
      valuser:integer;
      tempuser:string;
      chageuser:string;
    //  biaozhi:boolean;
    begin
    //解密过程
      try
      tempuser:=str;
      chageuser:='';
      for i:=1 to length(tempuser) do
      begin
        biaozhi:=true;
        valuser := Ord(tempuser[i]);
        for j:=0 to 61 do
        begin
          if valuser=asci[j] then
          begin
            biaozhi:=false;
            if j-2*i>=0 then
              valuser:=asci[j-2*i]
            else if i>30 then
            begin
              Application.MessageBox('用户名不能超过30位!','警告',mb_OK);
              exit;
            end
            else
              valuser:=asci[j-2*i+62];
            chageuser:=chageuser+chr(valuser);
            break;
          end;
        end;
        if biaozhi then
        begin
          Application.MessageBox('用户名必须为数字或字母!','警告',mb_OK);
          result:=':)';
          exit;
        end;
      end;
      result:=chageuser;
      except
        Application.MessageBox('用户名解密失败,请重新登录系统!','错误',mb_OK);
      end;
    end;
      

  7.   

    function Encrypt(s, Pwd: string): string;
    function Decrypt(s, Pwd: string): string;implementationuses ElAES;//这是Eldos 的 ElPack的一个单元,如果你找不到给我短信。function Encrypt(s, Pwd: string): string;
        function StringToHex(S: string): string;
        var i: integer;
        Begin
            Result := '';
                for i := 1 to Length( S ) do
                Result := Result + IntToHex( Ord( S[i] ), 2 );
        end;
    var
      Source: TStringStream;
      Dest: TStringStream;
      Size: integer;
      Key: TAESKey128;begin
      Source := TStringStream.Create( S );
      Dest   := TStringStream.Create( '' );
      try
        Size := Source.Size;
        Dest.WriteBuffer( Size, SizeOf(Size) );
        FillChar( Key, SizeOf(Key), 0 );
        Move( PChar( Pwd )^, Key, Min( SizeOf( Key ), Length( Pwd )));
        EncryptAESStreamECB( Source, 0, Key, Dest );
        Result:= StringToHex( Dest.DataString );  finally
        Source.Free;
        Dest.Free;
      end;
    end;function Decrypt(s, Pwd: string): string;
        function HexToString(S: string): string;
        var i: integer;
        Begin
          Result := '';
          for i := 1 to Length( S ) do
          begin
                if ((i mod 2) = 1) then
                        Result := Result + Chr( StrToInt( '0x' + Copy( S, i, 2 )));
          end;
        end;
    var
      Source: TStringStream;
      Dest: TStringStream;
      Size: integer;
      Key: TAESKey128;begin
      Source := TStringStream.Create( HexToString( s ));
      Dest   := TStringStream.Create( '' );  try
        Size := Source.Size;
        Source.ReadBuffer(Size, SizeOf(Size));
        FillChar(Key, SizeOf(Key), 0);
        Move(PChar( Pwd )^, Key, Min(SizeOf(Key), Length( Pwd )));
        DecryptAESStreamECB(Source, Source.Size - Source.Position, Key, Dest);
        Result := Dest.DataString;
      finally
        Source.Free;
        Dest.Free;
      end;
    end;
      

  8.   

    去51delphi找一个加密控件就行了