迅雷、快车、旋风加解密

<?php
function encrypt($url = null, $type = "thunder"){
 $types = array("thunder", "flashget", "qqdl");
 $type = strtolower($type);
 $url = trim($url);
 if ($url == null) return null;
 if (false == array_search($type, $types)) $type = "thunder";
 
 switch ($type){
  case "thunder":
   $url = "thunder://" . base64_encode("AA".$url."ZZ");
   break;
  case "flashget":
   $url = "flashget://" . base64_encode("[FLASHGET]".$url."[FLASHGET]") . "&bao";
   break;
  case "qqdl":
   $url = "qqdl://" . base64_encode($url);
   break;
 }
 return $url;
}

function decrypt($url_origin = null){
 $url = trim($url_origin);
 if ($url == null) return null;
 $count = preg_match("/(\w+):\/\//i", $url, $matches);
 if($count == 0 || $count == false){
  return $url_origin;
 }else{
  $type = strtolower($matches[1]);
 }

 $count = preg_match("/:\/\/([a-zA-Z0-9+\/]+={0,2})/i", $url, $matches);
 if($count == 0 || $count == false){
  return $url_origin;
 }else{
  $url = $matches[1];
 }
 switch ($type){
  case "thunder":
   $url = base64_decode($url);
   $count = preg_match("/AA(.+)ZZ$/i", $url, $matches);
   if($count == 0 || $count == false){
    return $url_origin;
   }else{
    $url = $matches[1];
   }
   break;
  case "flashget":
   $url = base64_decode($url);
   $count = preg_match("/\[FLASHGET\](.+)\[FLASHGET\]/i", $url, $matches);
   if($count == 0 || $count == false){
    return $url_origin;
   }else{
    $url = $matches[1];
   }
   break;
  case "qqdl":
   $url = base64_decode($url);
   break;
  default:
   return $url_origin;
 }
 return $url;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="utf-8">
<head>
<title>迅雷、快车、旋风加解密</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="all" />
</head>
<body>
<style type="text/css">
body{
 text-align:center;
 padding-top:50px;
}
#tb{
 background-color:green;
 margin:10px auto;
}
#result{
 text-align:left;
 width:60%;
 margin:10px auto;
}
</style>
 <div id="link">
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
   <table id="tb">
   <tr><td>链接</td><td colspan=2><textarea rows=3 name="url"></textarea></td></tr>
   <tr><td ><input type="radio" name="endecode" value="decode" id="decode" checked><label for="decode">解密</label></td><td><input type="radio" name="endecode" value="encode" id="encode"><label for="encode">加密</label></td><td></td></tr>
   <tr><td><input type="radio" name="type" value="thunder" checked>迅雷</td><td><input type="radio" name="type" value="flashget">快车</td><td><input type="radio" name="type" value="qqdl">QQ旋风</td></tr>
   <tr><td><input type="submit" name="submit" value="确定"></td><td><input type="reset" name="reset"></td><td></td></tr>
   </table>
  </form>
 </div>
 <div id = "result">
 <?php
 if(isset($_POST['endecode']) && isset($_POST['type']) && isset($_POST['url'])){
  $url = $_POST['url'];
  $type = $_POST['type'];
  $endecode = $_POST['endecode'];
  if($endecode == "decode"){
   $url2 = decrypt($url);
   echo "<p>解密前的地址: $url </p>";
   echo "<p>解密后的地址: $url2 </p>";
  }elseif($endecode == "encode"){
   $url2 = encrypt($url,$type);
   echo "<p>加密前的地址: $url </p>";
   echo "<p>加密后的地址: $url2 </p>";
  }
 }
 ?>
 </div>
</html>

 

posted @ 2013-11-25 12:52  perseus  阅读(353)  评论(0编辑  收藏  举报