PHP5 numeric string plus decryption code _php tips

Source: Internet
Author: User


<?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: Simple encryption and decryption of digital strings
* ----------------------------------------------------------------------------*/

Class Encryption {
/**
* Final ciphertext code, can be set to any repeat 10-bit English characters a-za-z
*/
Private $replacement = ' urskydmeiv ';

/**
* Added ciphertext first, can be set to 1 digits except 0 integers, that is 1-9
*/
Private $prefix = "8";

/**
* Public key, a positive integer less than 8 bits in length
*/
Private $match = "111111";

/**
* After conversion of the comparison 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;
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.