Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encryption PHP Script

Status
Not open for further replies.

rejoice

MIS
Jun 5, 2002
42
MY
Is there any PHP script that can help me to generate a fix length cipher text and decrypt it as well?

By the way, my server does not support any DES, AES, mcrypt...etc that provided by PHP... :-(
 
Here's a simple class that works well:
Code:
<?php 
/**
* Simple 2-way encryption class
*/
class rc4crypt {

function endecrypt ($pwd, $data, $case='') {
	if ($case == 'de') {
		$data = urldecode($data);
	}
	$key[] = &quot;&quot;;
	$box[] = &quot;&quot;;
	$temp_swap = &quot;&quot;;
	$pwd_length = 0;
	$pwd_length = strlen($pwd);
	for ($i = 0; $i <= 255; $i++) {
		$key[$i] = ord(substr($pwd, ($i % $pwd_length), 1));
		$box[$i] = $i;
	}
	$x = 0;
	for ($i = 0; $i <= 255; $i++) {
		$x = ($x + $box[$i] + $key[$i]) % 256;
		$temp_swap = $box[$i];
		$box[$i] = $box[$x];
		$box[$x] = $temp_swap;
	}
	$temp = &quot;&quot;;
	$k = &quot;&quot;;
	$cipherby = &quot;&quot;;
	$cipher = &quot;&quot;;
	$a = 0;
	$j = 0;
	for ($i = 0; $i < strlen($data); $i++) {
		$a = ($a + 1) % 256;
		$j = ($j + $box[$a]) % 256;
		$temp = $box[$a];
		$box[$a] = $box[$j];
		$box[$j] = $temp;
		$k = $box[(($box[$a] + $box[$j]) % 256)];
		$cipherby = ord(substr($data, $i, 1)) ^ $k;
		$cipher .= chr($cipherby);
	}
	if ($case == 'de') {
		$cipher = urldecode(urlencode($cipher));
	} else {
		$cipher = urlencode($cipher);
	}
	return $cipher;
}
}
?>

You need a pass phrase to en/decrypt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top