...

View Full Version : ecryption and decryption class problem



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;
}
}

meth
01-05-2007, 01:04 PM
I tested your class after I changed html_encode() & html_decode() to use htmlentities() and html_entity_decode() respectively instead. I also used charset utf-8 in the DTD. Worked fine.

--{edit}cancel that, after refreshing the page and producing new url's to click about 20 times, one of the get values were short a char; another 15-20 refreshes and one get var failed to set. So ya, I still recon it's an occasional char getting through that's not supported{/edit}--

CstAn
01-05-2007, 02:07 PM
I tested your class after I changed html_encode() & html_decode() to use htmlentities() and html_entity_decode() respectively instead. I also used charset utf-8 in the DTD. Worked fine.

--{edit}cancel that, after refreshing the page and producing new url's to click about 20 times, one of the get values were short a char; another 15-20 refreshes and one get var failed to set. So ya, I still recon it's an occasional char getting through that's not supported{/edit}--

i also faced some situation.

can anyone help me correct it????



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum