Viewing file: encriptacion.php (1.13 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
class Encriptor
{
# The key (for security reason, it must be private)
private $Key='7CABALLOSVIENENDEBONANZA';
// Generates the key
public function __construct($Key = '7CABALLOSVIENENDEBONANZA') {
$Key = str_split(md5($Key), 1);
$signal = false;
$sum = 0;
foreach($Key as $char) {
if($signal) {
$sum -= ord($char);
$signal = false;
} else {
$sum += ord($char);
$signal = true;
}
}
if($sum < 0) $sum *= -1;
$this->Key = $sum;
}
// Encrypt
public function encrypt($text) {
$text=base64_encode($text);
$text = str_split($text, 1);
$final = NULL;
foreach($text as $char) $final .= sprintf("%03x", ord($char) + $this->Key);
return $final;
}
// Decrypt
public function decrypt($text) {
$final = NULL;
$text = str_split($text, 3);
foreach($text as $char) $final .= chr(hexdec($char) - $this->Key);
return base64_decode($final);
}
}
?>
|