如题:求解百度地图经纬度加解密方法

解决方案 »

  1.   

    最简单的,就是使用查表法:......
    var
      Form1: TForm1;implementationconst Secretkey='9762801435';
    var wd_Encryption,jd_Encryption,
        wd_Decrypt,jd_Decrypt:string;{$R *.dfm}function TForm1.Encryption(s: ansistring): ansistring;//加密
    var i:integer;
    begin
      try
        for i:=1 to length(s) do begin
          if s[i]='.' then Result:=Result+'.'
          else Result:=Result+ Secretkey[strtoint(s[i])];
        end;
      except
        Result:='';
      end;
    end;function TForm1.Decrypt(s: ansistring): ansistring;//解密
    var i:integer;
    begin
      try
        for i:=1 to length(s) do begin
          if s[i]='.' then Result:=Result+'.'
          else Result:=Result+ inttostr(pos(s[i],Secretkey));
        end;
      except
        Result:='';
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);//获取加密后的坐标
    begin
      wd_Encryption:=Encryption(centerweidu.innerText);//经度
      jd_Encryption:=Encryption(centerjingdu.innerText);//维度
    end;procedure TForm1.Button2Click(Sender: TObject);//获取解密后的坐标
    begin
      wd_Decrypt:=Decrypt(wd_Encryption);//经度
      jd_Decrypt:=Decrypt(jd_Encryption);//维度
    end;
    ......
      

  2.   

    噢,少考虑了0的值,勘正:......
    var
      Form1: TForm1;implementationconst Secretkey='9762801435';
    var wd_Encryption,jd_Encryption,
        wd_Decrypt,jd_Decrypt:string;{$R *.dfm}function TForm1.Encryption(s: ansistring): ansistring;//加密
    var i:integer;
    begin
      try
        for i:=1 to length(s) do begin
          if s[i]='.' then Result:=Result+'.'
          else Result:=Result+ Secretkey[strtoint(s[i])+1];
        end;
      except
        Result:='';
      end;
    end;function TForm1.Decrypt(s: ansistring): ansistring;//解密
    var i:integer;
    begin
      try
        for i:=1 to length(s) do begin
          if s[i]='.' then Result:=Result+'.'
          else Result:=Result+ inttostr(pos(s[i],Secretkey)-1);
        end;
      except
        Result:='';
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);//获取加密后的坐标
    begin
      wd_Encryption:=Encryption(centerweidu.innerText);//经度
      jd_Encryption:=Encryption(centerjingdu.innerText);//纬度
    end;procedure TForm1.Button2Click(Sender: TObject);//获取解密后的坐标
    begin
      wd_Decrypt:=Decrypt(wd_Encryption);//经度
      jd_Decrypt:=Decrypt(jd_Encryption);//纬度
    end;
    ......