zoukankan      html  css  js  c++  java
  • 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; 
    }
    }
    ?>
    欢迎各位指点!
  • 相关阅读:
    数组中只出现一次的数字
    平衡二叉树
    二叉树的深度
    数字在排序数组中出现的次数
    数组中的逆序对
    第一个只出现一次的字符位置
    丑数
    把数组排成最小的数/1038. Recover the Smallest Number
    python系统编程(十一)
    python系统编程(十)
  • 原文地址:https://www.cnblogs.com/thors/p/9494149.html
Copyright © 2011-2022 走看看