Location: PHPKode > scripts > Encryptor > encryptor/class.encriptor.php
<?php
/***
*
* Cryptography class
* By Wanderson Regis Silva <hide@address.com>
* Copyright (c) 2008 Wanderson Regis Silva
* File version: 1.0
* This file is under GNU General Public License
*
***/

class Encriptor
{
	# The key (for security reason, it must be private)
	private $Key;

	// Generates the key
	public function __construct($Key = '') {
		$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 = 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 $final;
	}
}
?>
Return current item: Encryptor