问题描述
原PHP函数functiondecodeaddr($p){$a=0;$s=0;$d=strlen($p);$f="";$g=-1;$h=0;$count=0;for($j=0;$j<$d;$j++){//for($j=20;$j<$d;$j++){$k=ord($p[$j]);$k=($k==95)?63:(($k==44)?62:(($k>=97)?($k-61):(($k>=65)?($k-55):($k-48))));$s=($s*LT_count2n(6))+$k;$a+=6;while($a>=8){$l=(int)($s/LT_count2n(($a-8)));if($h>0){$g=($g*LT_count2n(6))+($l&(0x3f));$h--;if($h==0){$f.=chr($g%256);$f.=chr($g/256);//echo$g."<br/>";}}else{if($l>=224){$g=$l&(0xf);$h=2;}elseif($l>=128){$g=$l&(0x1f);$h=1;}else{$f.=chr($l%256);$f.=chr($l/256);//echo$l."<br/>";};};$s=$s-($l*LT_count2n(($a-8)));$a-=8;};};returniconv('UCS-2LE','UTF-8',$f);};
用.net重写的函数:privatestringDecodeAddr(stringp){inta=0;ints=0;intd=p.Length;StringBuilderf=newStringBuilder();intg=-1;inth=0;intcount=0;inti=0;//intk=0;EncodingUCS2=Encoding.GetEncoding("UCS-2");//for(intj=20;j<d;j++)for(intj=0;j<d;j++){intk=Convert.ToInt32(p[j]);k=(k==95)?63:((k==44)?62:((k>=97)?(k-61):((k>=65)?(k-55):(k-48))));s=(s*Count2n(6))+k;a+=6;while(a>=8){i=(int)(s/Count2n((a-8)));if(h>0){g=(g*Count2n(6))+(i&(0x3f));h--;if(h==0){f.Append((char)(g%256));f.Append((char)(g/256));}}else{if(i>=224){g=i&(0xf);h=2;}elseif(i>=128){g=i&(i%0x1f);h=1;}else{f.Append((char)(i%256));f.Append((char)(i/256));}}s=s-(i*Count2n((a-8)));a-=8;}}returnEncoding.Default.GetString(Encoding.Convert(Encoding.GetEncoding("UCS-2"),Encoding.UTF8,Encoding.UTF8.GetBytes(f.ToString())));}
其中两个函数的参数都为:vRc_vBYSvvo1vBYjvR6nvRY2xxoCvRwtvwU0wBUlwPc4wB,HxxoCvPscvhIovQwUwPcfvBYjvQscvOoNvxgcCJWmvx6pvQI4但是解析出来值不一样 我用.net重写的解析出来有一部分是乱码 求各位大哥指点
解决方案
解决方案二:
补充两个函数:php的functionLT_count2n($n){$i=1;$num=1;while($i<=$n){$num=$num*2;$i++;}return$num;}
.net的:privateintCount2n(intnum){inti=1;intnumber=1;while(i<=num){number=number*2;i++;}returnnumber;}
求各位大牛指导在线等急谢谢