<? Php
/*----------------------------------------------------------------------------
* Script Name: encrypt. php
* Creation Date:
* Last Modified:
* Author: meyu
* Copyright (c) 2007
* Purpose: simple encryption and decryption of numeric strings
*----------------------------------------------------------------------------*/
Class Encryption {
/**
* The final ciphertext code can be set to any non-repeated 10-character a-zA-Z
*/
Private $ replacement = 'urskydmeiv ';
/**
* The first added ciphertext can be set to an 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 ";
/**
* 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 ($ str, $ I * 8, 8) + 0) ^ $ this-> match, 1 );
$ I ++;
}
Return $ str_out;
}
}
?>