Home > Backend Development > PHP Tutorial > php5 download php5 numeric string encryption and decryption code

php5 download php5 numeric string encryption and decryption code

WBOY
Release: 2016-07-29 08:37:59
Original
736 people have browsed it

/* ----------------------------------------------------------------------------
* 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 {
    /**
    * The final ciphertext code can be set to any non-repeating 10-digit English characters a-zA-Z
 */
    private $replacement = 'urskydMeIV';
    /**
   * The first bit of the added ciphertext can be set to a 1-digit integer other than 0, that is, 1-9
 */
    private $prefix = "8";
    /**
      * Public key, a positive integer with a length less than 8 digits
    */
    private $match = "111111";
    /**
    * Compare array after conversion
    */
    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;
    }
}
?>

以上就介绍了php5下载 php5数字型字符串加解密代码,包括了php5下载方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template