paip.URL参数压缩64进制

paip.URL参数压缩64进制

有时候URL参数经过编码是16进制的,这样会比较长,可以使用64进制来压缩一下。。约可以减少30%。。。

比如admin,这个字串,经过加密后是D7D5E2DACF,增长了一倍。。我们可以用64进制来来压缩一下,得到的结果是19Xi2sP

主要过程是:
1.把此字串每三个分为一组,
2.然后每组转为64进制。。再连接起来就行了。
3.转码对照串来自于BASE64,不过考虑到URL传输的实际情况把最后两们+/变成了@$,这样就可以不用URL ENCODE就可以直接http传输。。

这里主要由ASP页面发起请求,PHP回应,所以编码是VBS写的,而解码是PHP写的..


------16进制转64过程(vbs)------
     const BASE_64_MAP_INIT_L718 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@$"
   
 ''16进制转64进制
     PUBLIC FUNCTION HEX64Encode(plain)
     
   dim msgarr,newstr
     msgarr=str2array_l718(plain,3)
     for i=0 to ubound(msgarr)
     dim numHex
      numHex=msgarr(i)
     dim newchar  'HEx64 format    
     newchar= tohex64(numHex)
     
     newstr=newstr+cstr(newchar)
     next 
          HEX64Encode = newstr
     END FUNCTION


-----------------解码过程----------------

 

 

//   ' 64进制转16进制
function  HEX64Decode($num)
{
 $msgarr=str_split($num,2); 
 $newstr="";
 
 for($i=0;$i< count ($msgarr);$i++){
  $v=$msgarr[$i];
  $keychar=hex64Tohex($v);//  'encode char
  
  $newstr=$newstr.$keychar;
 } 
 
 return $newstr;
 
}
$BASE_64_MAP_INIT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@$";

//单个数  ONLY
function hex64Tohex($num) { // Xi
 global $BASE_64_MAP_INIT;
 $BASE_64_MAP_INIT_arr = str_split ( $BASE_64_MAP_INIT );
 $numarr = str_split ( $num );
 $numDec=0;
 if (count ( $numarr ) == 1) {
  $first = $numarr [0];
  $firstIndex = strpos ( $BASE_64_MAP_INIT, $first );
  $numDec = $firstIndex;
 } else {
  $first = $numarr [0];
  $sencond = $numarr [1];
  $firstIndex = strpos ( $BASE_64_MAP_INIT, $first );
  $sencondIndex = strpos ( $BASE_64_MAP_INIT, $sencond );
  $firstNum = $firstIndex * 64;
  $numDec = $firstNum + $sencondIndex;
 }
 $numHex = dechex ( $numDec );
 
 return $numHex;
}

posted @ 2012-07-18 15:23  attilaxAti  阅读(22)  评论(0编辑  收藏  举报