<code><?php<br />$key = "This is supposed to be a secret key !!!";<br />function keyED($txt,$encrypt_key)<br />{<br />$encrypt_key = md5($encrypt_key);<br />$ctr=0;<br />$tmp = "";<br />for ($i=0;$i<strlen($txt);$i++)<br />{<br />if ($ctr==strlen($encrypt_key)) $ctr=0;<br />$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);<br />$ctr++;<br />}<br />return $tmp;<br />}<br />function encrypt($txt,$key)<br />{<br />srand((double)microtime()*1000000);<br />$encrypt_key = md5(rand(0,32000));<br />$ctr=0;<br />$tmp = "";<br />for ($i=0;$i<strlen($txt);$i++)<br />{<br />if ($ctr==strlen($encrypt_key)) $ctr=0;<br />$tmp.= substr($encrypt_key,$ctr,1) .<br />(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));<br />$ctr++;<br />}<br />return keyED($tmp,$key);<br />}<br />function decrypt($txt,$key)<br />{<br />$txt = keyED($txt,$key);<br />$tmp = "";<br />for ($i=0;$i<strlen($txt);$i++)<br />{<br />$md5 = substr($txt,$i,1);<br />$i++;<br />$tmp.= (substr($txt,$i,1) ^ $md5);<br />}<br />return $tmp;<br />}<br />$string = "Hello World !!!";<br />// encrypt $string, and store it in $enc_text<br />$enc_text = encrypt($string,$key);<br />// decrypt the encrypted text $enc_text, and store it in $dec_text<br />$dec_text = decrypt($enc_text,$key);<br />print "Original text : $string <Br>";<br />print "Encrypted text : $enc_text <Br>";<br />print "Decrypted text : $dec_text <Br>";<br />?></code>