其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
一个PHP写的字符串混淆类~~^^

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

上个礼拜和一个同事一起做个项目,我有一个字符串要传给他,考虑到安全问题,决定混淆一下再传,所以临时写了这个混淆字符串的类。同事原本用C#写好了个类似的,我在原有基础上改写成了PHP的 ^^
下载地址 http://phpjoe.512j.com/disarrange_class.rar
在此要感谢 Arron Wong ^^

<?

//////////////////////////////////////////////////////////////////////////////////////////////////////
//
//         Programmed by Verne Joe on 2005-01-15.
//         Thankfulness to Arron Wong. He told me the arithmetic ^^
//
//////////////////////////////////////////////////////////////////////////////////////////////////////

class disarrange{
      var $arr;

      //constructed function and turn string into array
      function disarrange($str){
         $string = preg_replace("/(.{1})/", "\\1,",$str);
         $this->arr = explode(",", substr($string, 0,-1));
      }

      //function for encrypting
      function encrypt(){
         $arr = $this->MakeIntArray($this->arr);
         for($i=0;$i<count($this->arr);$i++){
             $ch = $this->arr[$i];
             $this->arr[$i] = $this->arr[$arr[$i]];
             $this->arr[$arr[$i]] = $ch;
         }
         return $this->revertToString($this->arr);
      }

      //function for decrypting
      function decrypt(){
         $arr = $this->MakeIntArray($this->arr);
         for($i=count($this->arr)-1;$i>=0;$i--){
             $ch = $this->arr[$i];
             $this->arr[$i] = $this->arr[$arr[$i]];
             $this->arr[$arr[$i]] = $ch;
         }
         return $this->revertToString($this->arr);
      }


      function MakeIntArray($arr){
         $confuse = new PseudoRandomizer(count($arr) * count($arr), count($arr));
         for($i=0;$i<count($arr);$i++){
              $arr[$i] = $confuse->Generate();
         }
         return $arr;
      }

      //revert array to string
      function revertToString($arr){
         $string = "";
         foreach ($arr as $str)
             $string.= $str;
         return $string;
      }
}


class PseudoRandomizer{
      var $seed;
      var $max;

      function PseudoRandomizer($seed,$max){
           $this->seed = $seed;
           $this->max = $max;
      }

      function Generate(){
           $newseed = ($this->seed * (3719/2)) + 3719;
           $newseed = $newseed % 65535;
           $this->seed = $newseed;
           return $this->seed % $this->max;
      }
}


?>

?>


相关文章

相关软件