最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php5數(shù)字型字符串加解密代碼

 更新時(shí)間:2008年04月24日 19:41:53   作者:  
對(duì)應(yīng)awk版加解密程序的PHP實(shí)現(xiàn)代碼


<?php
/* ----------------------------------------------------------------------------
* Script Name: encrypt.php
* Creation Date: 2008-4-7 10:36
* Last Modified: 2008-4-12 16:00
* Author: meyu
* Copyright (c) 2007
* Purpose: 數(shù)字字符串簡(jiǎn)易加解密
* ----------------------------------------------------------------------------*/

class Encryption {
    /**
     * 最終的密文代碼,可設(shè)為任意不重復(fù)的10位英文字符a-zA-Z
     */
    private $replacement = 'urskydMeIV';

    /**
     * 增加的密文第一位,可設(shè)為1位除0以外的整數(shù),即 1-9
     */
    private $prefix = "8";

    /**
     * 公鑰,長(zhǎng)度小于8位的正整數(shù)
     */
    private $match = "111111";

    /**
     * 轉(zhuǎn)換后對(duì)照數(shù)組
     */
    private $replaceenc;
    private $replacedec;

    function __construct() {
        for($i =0; $i < 10; $i++) {
            $this->replaceenc['/'.$i.'/'] = $this->replacement{$i};
            $this->replacedec['/'.$this->replacement{$i}.'/'] = $i;
        }
    }

    public function encrypt($str) {
        return preg_replace(
            array_keys($this->replaceenc),
            $this->replaceenc,
            $this->mynotin(preg_replace("/(.)(.)/", "${2}${1}", $str))
        );
    }

    public function decrypt($str) {
        return preg_replace("/(.)(.)/", "${2}${1}",
            $this->mynotout(preg_replace(array_keys($this->replacedec),$this->replacedec,$str))
        );
    }

    private function mynotin($str) {
        $str_out = "";
        $i = 0;
        while(isset($str{7*$i})) {
            $str_out .= (($this->prefix.substr($str, $i*7, 7))+0)^$this->match;
            $i++;
        }
        return $str_out;
    }

    private function mynotout($str) {
        $str_out = "";
        $i = 0;
        while(isset($str{8*$i})) {
            $str_out .= substr((substr($str, $i*8, 8)+0)^$this->match, 1);
            $i++;
        }
        return $str_out;
    }
}
?>

相關(guān)文章

最新評(píng)論

集贤县| 辽宁省| 新巴尔虎左旗| 平果县| 佳木斯市| 崇阳县| 临海市| 南丹县| 北宁市| 巴南区| 上饶县| 榆中县| 鹿邑县| 东城区| 巴塘县| 平山县| 象山县| 青神县| 冀州市| 庐江县| 晋江市| 平谷区| 北辰区| 四平市| 天津市| 山丹县| 裕民县| 永州市| 防城港市| 河东区| 泾阳县| 云安县| 南华县| 武冈市| 麻城市| 饶河县| 金昌市| 苏尼特左旗| 泰顺县| 榕江县| 环江|