php支持解密的加密算法示例

其实只是对位运算符的一种简单的应用。

<?php
class Helper_Inpass{
  private $keys='thisismytoken';//token
  function inpass($txt) {//加密
    srand((double)microtime() * 1000000); 
    $encrypt_key = md5(rand(0, 32000)); 
    $ctr = 0; 
    $tmp = ''; 
    for($i = 0;$i < strlen($txt); $i++) { 
      $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; 
      $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]); 
    } 
  return base64_encode($this->passport_key($tmp)); 
}
function depass($txt) { //解密
  $txt = $this->passport_key(base64_decode($txt)); 
  $tmp = ''; 
  for($i = 0;$i < strlen($txt); $i++) { 
    $md5 = $txt[$i]; 
    $tmp .= $txt[++$i] ^ $md5;
  }
  return $tmp; 
}
private function passport_key($txt) { 
  $encrypt_key = md5($this->keys); 
  $ctr = 0; 
  $tmp = ''; 
  for($i = 0; $i < strlen($txt); $i++) { 
    $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; 
    $tmp .= $txt[$i] ^ $encrypt_key[$ctr++]; 
  }
  return $tmp; 
}
}
?>

 

posted @ 2018-08-17 16:42  寻觅~~  阅读(329)  评论(0编辑  收藏  举报