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 8 of 8
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    Decryption Problems

    I have an encryption function and a decryption function as part of my credit card class.
    The decryption function is passed a value and a key.
    If the decryption function is called from the encryption function, it works perfectly.
    If the result of the encryption is converted into a string ($v[0].$v[1]) and stored as $this->encryptedNumber then later split in 2 and passed to the decryption function with the same key, it doesnt work.
    I printed out both arrays that were passed in and they are both identical.
    I'm absolutely baffled as to what the problem is.

    PHP Code:
      function encrypt()
      {
         
    $k $this->getKey();
         
    $v explode("\r\n"chunk_split($this->numberceil(strlen($this->number)/2)));
         
    $this->xteaEncrypt($v$k);
      }


      function 
    decrypt()
      {
        
    $k $this->getKey();
        
    $v explode("\r\n"chunk_split($this->encryptedNumberceil(strlen($this->encryptedNumber)/2)));

        
    $this->xteaDecrypt($v$k);
        
      }

      function 
    getKey()
      {
         
    $k[0] = "123456789012345";
    $k[1] = "678901234567890";
    $k[2] = "987654321098765";
    $k[3] = "432109876543210";
         return 
    $k;
      }
      
    function 
    xteaEncrypt($v$k) {
         
    $sum 0;
         
    $delta 0x9E3779B9;
         for(
    $i=0$i<32$i++) {
             
    $v[0] += unsigned(($v[1] << $v[1] >> 5) + $v[1] ^ $sum $k[$sum 3]);
             
    $sum += $delta;
             
    $v[1] += unsigned(($v[0] << $v[0] >> 5) + $v[0] ^ $sum $k[$sum>>11 3]);
         }
        
    $this->encryptedNumber $v[0].$v[1];
        
    $this->xteaDecrypt($v$k);
     }
     
    function 
    xteaDecrypt($v$k) {
          
    print_r($v)."<br />";
          
    print_r($k)."<br />";
         
    $sum 0xC6EF3720;
         
    $delta 0x9E3779B9;
         for(
    $i=0$i<32$i++) {
             
    $v[1] -= unsigned(($v[0] << $v[0] >> 5) + $v[0] ^ $sum $k[$sum>>11 3]);
             
    $sum -= $delta;
             
    $v[0] -= unsigned(($v[1] << $v[1] >> 5) + $v[1] ^ $sum $k[$sum&3]);
         }
         echo 
    "<br />Funct Decrypted:".$v[0].$v[1]."<br />";
         
    $this->number $v[0].$v[1];
     }
    function 
    unsigned($val)
    {
      
    $val $val*$val;
      
    $val sqrt($val);
      return 
    $val;
      


  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I've compared the two, I've printed out the ascii character codes for each character in the array and they still come out the same. But the decryption comes out different.

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I've narrowed down the problem to being that there is some whitespace being lost here:

    $this->number = $v[0].$v[1];

    doesnt anyone know how I can preserve that white space?

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    total guess

    $this->number = "{$v[0]}.{$v[1]}";

    or cast everything as (string)$v[0] etc , otherwise not a clue
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    tried the first one, havent tried casting it as a string. WIll give it a go in the morning.

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    that didnt work either :S

    Theres got to be a way to preserve that data.... hmmm maybe thats why I didnt find a php version of xTEA

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #8
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    I wish my german was better lol
    I know it shouldnt matter but for some reason its really off-putting


  •  

    Posting Permissions

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