色尼玛亚洲综合影院,亚洲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數字型字符串加解密代碼,轉載需保留來源!

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

主站蜘蛛池模板: 邢台市| 南江县| 萍乡市| 唐山市| 清水河县| 迁西县| 大余县| 湖口县| 金堂县| 镇康县| 平泉县| 赤城县| 馆陶县| 湖州市| 济宁市| 灵石县| 涟水县| 安泽县| 尚义县| 石嘴山市| 巍山| 资源县| 青浦区| 五家渠市| 耒阳市| 兴隆县| 祁阳县| 神池县| 闽清县| 达日县| 双鸭山市| 无锡市| 英德市| 广河县| 景东| 江达县| 汝城县| 海安县| 平山县| 白河县| 彰武县|