Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts

    ecryption and decryption class problem

    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:
    PHP Code:
    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;
             }
        } 

  • #2
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    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}--
    Last edited by meth; 01-05-2007 at 02:19 PM. Reason: further testing
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by meth View Post
    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????


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •