PhpSnip.com

User Stats

TransCrypt Encrytion functions

TransCrypt is an encrytion library. It simply uses look up tables to translate bytes. The look up tables are generated by the LFSR algorithm.

Info

 Download  View Source (print view)
 Rating : 4.7  Views : 410

Source Code ( 44 lines )

<?
/* 
TransCrypt Encrytion functions

Description: TransCrypt is an encrytion library. It simply uses look up tables to translate bytes. The look up tables are generated by the LFSR algorithm.

Example:

include("trans_crypt.php");
$secret = "I like encrytion";
$crypted_data = trans_encrypt($secret);
$decrypted_data = trans_decrypt($crypted_data);
echo "secret = $decrypted_data";

*/

function trans_encrypt($data){
	for($i = 0, $key = 27, $c = 48; $i <= 255; $i++){
		$c = 255 & ($key ^ ($c << 1));
		$table[$key] = $c;
		$key = 255 & ($key + 1);
	}
	$len = strlen($data);
	for($i = 0; $i < $len; $i++){
		$data[$i] = chr($table[ord($data[$i])]);
	}
	return base64_encode($data);
}

function trans_decrypt($data){
	$data = base64_decode($data);
	for($i = 0, $key = 27, $c = 48; $i <= 255; $i++){
		$c = 255 & ($key ^ ($c << 1));
		$table[$c] = $key;
		$key = 255 & ($key + 1);
	}
	$len = strlen($data);
	for($i = 0; $i < $len; $i++){
		$data[$i] = chr($table[ord($data[$i])]);
	}
	return $data;
}

?>

Search

Subscribe

  Rss Feeds

Sponsors

Advertise