<?php
class cryptit{

	var $s_array = array();
	var $k_array = array();
	var $return_val;
	var $num_count;
	var $alp_count;
	var $lwr_count;

	function get_ascii_val($passed_val)
	{
		for($x_val = 0; $x_val <= 255; $x_val = $x_val + 1) {
			$asc_chars[chr($x_val)] = $x_val; 
		}
		return $asc_chars[$passed_val];
	} 

	function encrypt_value($input_val, $key_val)
	{
		for ($i = 0; $i <= 255; $i = $i + 1) {
			$s_array[$i] = $i;
		} 

		$j = 1;
		for ($i = 0; $i <= 255; $i = $i + 1){
			if ($j > strlen($key_val)) {
				$j = 1;
			}
			$k_array[$i]	= $this -> get_ascii_val(substr($key_val, $j, 1));
			$j				= $j + 1;
		}

		$j = 0;
		for ($i = 0; $i <= 255; $i = $i + 1) {
			$j			 = ($j + $s_array[$i] + $k_array[$i]) % 256;
			$temp_var	 = $s_array[$i];
			$s_array[$i] = $s_array[$j];
			$s_array[$j] = $temp_var;
		}

		$i		= 0;
		$j		= 0;
		for ($x = 0; $x < strlen($input_val); $x++) {
			$i				= ($i + 1) % 256;
			$j				= ($j + $s_array[$i]) % 256;
			$temp_var		= $s_array[$i];
			$s_array[$i]	= $s_array[$j];
			$s_array[$j]	= $temp_var;
			$t				= ($s_array[$i] + ($s_array[$j] % 256)) % 256;
			$y				= $s_array[$t];
			$comp_val		= $this->get_ascii_val(substr($input_val, $x, 1)) ^ $y;
			$calc_val		= Chr($this->get_ascii_val(substr($input_val, $x, 1)) ^ $y);
			$return_val		= $return_val.$calc_val;
		}
		return $return_val;
	}
}
?>