CstAn
01-05-2007, 10:15 AM
i try ecrypt and pass d data through the url.
when i decrypt with the value i get, some time i can the origninal value and some time cant.
can anyone tell me y??
Both process i was using html_encrypt and html_dencrypt function listed below.
thanks a lot.
the following was the class:
class cls_encrypt {
var $_key;
function cls_encrypt() {
$this->_key = "SWeaTEquITyiNV_pASswORd^!%@$#KeY";
return 1;
}
function keyED($txt) {
$encrypt_key = md5($this->_key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}
function html_encrypt ($txt) {
return urlencode($this->encrypt($txt));
}
function encrypt($txt) {
srand((double)microtime()*1000000);
$encrypt_key = md5(rand(0,32000));
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) .
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr++;
}
return $this->keyED($tmp);
}
function html_decrypt($txt) {
return $this->decrypt(urldecode($txt));
}
function decrypt($txt) {
$txt = $this->keyED($txt);
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
$md5 = substr($txt,$i,1);
$i++;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
return $tmp;
}
}
when i decrypt with the value i get, some time i can the origninal value and some time cant.
can anyone tell me y??
Both process i was using html_encrypt and html_dencrypt function listed below.
thanks a lot.
the following was the class:
class cls_encrypt {
var $_key;
function cls_encrypt() {
$this->_key = "SWeaTEquITyiNV_pASswORd^!%@$#KeY";
return 1;
}
function keyED($txt) {
$encrypt_key = md5($this->_key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}
function html_encrypt ($txt) {
return urlencode($this->encrypt($txt));
}
function encrypt($txt) {
srand((double)microtime()*1000000);
$encrypt_key = md5(rand(0,32000));
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) .
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr++;
}
return $this->keyED($tmp);
}
function html_decrypt($txt) {
return $this->decrypt(urldecode($txt));
}
function decrypt($txt) {
$txt = $this->keyED($txt);
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
$md5 = substr($txt,$i,1);
$i++;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
return $tmp;
}
}