/* ----------------------------------------------------------------------------
* Script Name:encrypt.php
* Creation date:2008-4-7 10:36
* Last modified:2008-4-12 16:00
* Author:meyu
* Copyright (c) 2007
* Purpose: Digital string simple plus decryption
* ----------------------------------------------------------------------------*/
Class Encryption {
/**
* The final ciphertext code, can be set to any non-repetition of the 10-bit English characters a-za-z
*/
Private $replacement = ' urskydmeiv ';
/**
* Added ciphertext first bit, can be set to 1 bits except 0 integer, that is, 1-9
*/
Private $prefix = "8";
/**
* Public key, positive integer less than 8 bits in length
*/
Private $match = "111111";
/**
* Post-conversion control array
*/
Private $replaceenc;
Private $replacedec;
function __construct () {
for ($i =0; $i < $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;
}
}
?>
The above describes the PHP5 download PHP5 digital string encryption and decryption code, including the content of the PHP5 download, I hope to be interested in PHP tutorial friends helpful.