对于安全性要求不高的情况下足够用了,性能从高到低的两种实现:
<?php
   function xor_enc($string, $operation, $key = 'abcdf') {
      $string = $operation == 'ENCODE' ? $string : base64_decode($string);
      $len1 = strlen($string);
      $len2 = strlen($key);
      if($len1 > $len2) $key = str_repeat($key, ceil($len1 / $len2));
      $string = $operation == 'ENCODE' ? base64_encode($string ^ $key) : $string ^ $key;
      return $string;
   }
?>   function xor_enc($string, $operation = 'ENCODE', $key = 'abcd') {
      $txt = $operation == 'ENCODE' ? $string : base64_decode($string);
      $len = strlen($key);
      $code = '';
      for ($i = 0; $i < strlen($string); $i ++) {
         $k = $i % $len;
         $code .= $string [$i] ^ $key [$k];
      }
      $code = $operation == 'ENCODE' ? base64_encode($code) : $code;
      return $code;
   }        标签:none