色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php5數字型字符串加解密代碼



<?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: 數字字符串簡易加解密
* ----------------------------------------------------------------------------*/

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

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

    /**
     * 公鑰,長度小于8位的正整數
     */
    private $match = "111111";

    /**
     * 轉換后對照數組
     */
    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;
    }
}
?>

php技術php5數字型字符串加解密代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 沈丘县| 八宿县| 灌云县| 辽源市| 建湖县| 博客| 大庆市| 承德县| 密云县| 西丰县| 班戈县| 宁乡县| 浦东新区| 建宁县| 融水| 东兴市| 灵寿县| 烟台市| 文安县| 封丘县| 宜春市| 旬邑县| 台州市| 安化县| 尼勒克县| 吉安县| 太保市| 农安县| 临汾市| 景谷| 保亭| 雅江县| 临泽县| 赤峰市| 中宁县| 宁强县| 水城县| 榆树市| 玉林市| 锡林浩特市| 灵山县|