我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > PHP专区 > php安装/入门 > 一个双向加密解密法(php)
热门文章排行
热门文章排行 检查email地址格式的代码(01-11)
PHP操作文件问答(01-11)
PHP安装攻略:安装并配置PHP(10-23)
PHP的十个高级技巧 4(10-23)
PHP控制语句(10-12)
精采文章排行
精采文章排行 PHP连接MYSQL的两种方法(11-15)
PHP和MySQL开发的8个技巧(10-23)
PHP安装攻略:安装并配置PHP(10-23)
php+mysql扎实个人基本功(10-23)
PHP编程常用技巧四则(10-23)
技术专题推荐
网管论坛交流
 

一个双向加密解密法(php) 

作者:佚名   来源:本站教程   点击:   日期:2007-01-11

基于进制转换的

<?
//made by huyang @2005-01-20||11-04-06
##用n进位制到m进位制
##0~9A-Z,最多可理解为36进制范围
print'<title>加密解密法</title>';
class carry
  {
    function carry($n,$m)
      {
 $this->n=$n;
 $this->m=$m;
 $this->chn['0']=0;
 $this->chn['1']=1;
 $this->chn['2']=2;
 $this->chn['3']=3;
 $this->chn['4']=4;
        $this->chn['5']=5;
        $this->chn['6']=6;
        $this->chn['7']=7;
        $this->chn['8']=8;
        $this->chn['9']=9;
        $this->chn['A']=10;
        $this->chn['B']=11;
        $this->chn['C']=12;
        $this->chn['D']=13;
        $this->chn['E']=14;
        $this->chn['F']=15;
        $this->chn['G']=16;
        $this->chn['H']=17;
        $this->chn['I']=18;
        $this->chn['J']=19;
        $this->chn['K']=20;
        $this->chn['L']=21;
        $this->chn['M']=22;
        $this->chn['N']=23;
        $this->chn['O']=24;
        $this->chn['P']=25;
        $this->chn['Q']=26;
        $this->chn['R']=27;
        $this->chn['S']=28;
        $this->chn['T']=29;
        $this->chn['U']=30;
        $this->chn['V']=31;
        $this->chn['W']=32;
        $this->chn['X']=33;
        $this->chn['Y']=34;
        $this->chn['Z']=35;
        $this->cn[0]='0';
        $this->cn[1]='1';
        $this->cn[2]='2';
        $this->cn[3]='3';
        $this->cn[4]='4';
        $this->cn[5]='5';
        $this->cn[6]='6';
        $this->cn[7]='7';
        $this->cn[8]='8';
        $this->cn[9]='9';
        $this->cn[10]='A';
        $this->cn[11]='B';
        $this->cn[12]='C';
        $this->cn[13]='D';
        $this->cn[14]='E';
        $this->cn[15]='F';
        $this->cn[16]='G';
        $this->cn[17]='H';
        $this->cn[18]='I';
        $this->cn[19]='J';
        $this->cn[20]='K';
        $this->cn[21]='L';
        $this->cn[22]='M';
        $this->cn[23]='N';
        $this->cn[24]='O';
        $this->cn[25]='P';
        $this->cn[26]='Q';
        $this->cn[27]='R';
        $this->cn[28]='S';
        $this->cn[29]='T';
        $this->cn[30]='U';
        $this->cn[31]='V';
        $this->cn[32]='W';
        $this->cn[33]='X';
        $this->cn[34]='Y';
        $this->cn[35]='Z';
      }
    function check1($a)
      {
 if(ereg("[0-9]",$a))
   if($a>=2)
     if($a<=36)
       return true;
 return false;
      }
    function check2($a)
      {
 $la=0;
 for($j=0;$j<strlen($a);$j++)
   {
     if($this->chn[substr($a,$j,1)]>=$this->n)
       $la=1;
     if($la)
       break;
   }
 if($la)
   return false;
 else
   return true;
      }
    function toDEC($a)//$n->十进制
      {
 if($this->n==10)
   return $a;
 else
   {
     $a=strrev($a);
     $k=0;
     for($i=0;$i<strlen($a);$i++)
       {
  $k+=$this->chn[substr($a,$i,1)]*pow($this->n,$i);
       }
     return $k;
   }
      }
    function gethigh($a)
      {
 if($a<=1)
   return 1;
 else
   {
     for($i=0;$i<100;$i++)
       {
  if(pow($this->m,$i)>$a)
    break;
       }
     return $i;
   }
      }
    function toM($a)//十进制->$m
      {
 $a1=$this->gethigh($a);
 $res="";
 for($i=1;$i<=$a1;$i++)
   {
     $u=($a-$a%pow($this->m,($a1-$i)))/(pow($this->m,($a1-$i)));
     $a-=$u*pow($this->m,($a1-$i));
     $res.=$this->cn[$u];
   }
 return $res;
      }
    function get($a)
      {
 if(!$this->n)$this->n=10;
 if(!$this->m)$this->m=10;
 if(($this->check1($this->n))&&($this->check1($this->m)))
   {
     if(ereg("[0-9A-Z]",$a))
       {
  if($this->check2($a))
    {
      return $this->toM($this->toDEC($a));
    }
  else
    return false;
 


文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·将OICQ数据转成MYSQL数据 ·用PHP实现ODBC数据分页显示一例
·php生成WAP页面 ·PHP与Javascript的两种交互方式
·PHP+Javascript模拟Matrix画面 ·WHOIS类的修改版

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。