Forum > General

Shr function - pascal and php

(1/4) > >>

xinyiman:
Question! But the SHR has problems?

Why I compared this function:

function PKV_GetKeyByte(const Seed : Int64; a, b, c : Byte) : Byte;
var
   risultato: byte;
begin
  a := a mod 25;
  b := b mod 3;
 if a mod 2 = 0 then
    risultato := ((Seed shr a) and $000000FF) xor ((Seed shr b) or c)
  else
    risultato := ((Seed shr a) and $000000FF) xor ((Seed shr b) and c);
    PKV_GetKeyByte:=risultato;
end;


I had to write this other function in php, but the results are different

   private function PKV_GetKeyByte($Seed,$a,$b,$c)
   {
      $a = $a % 25;
        $b = $b % 3;
       if(  $a % 2 == 0 )
       {
          $result = ( ( $Seed >> $a ) && 0x000000FF ) xor ( ( $Seed >> $b ) || $c );
       }else
       {
          $result = ( ( $Seed >> $a ) && 0x000000FF ) xor ( ( $Seed >> $b ) && $c );
       }       
      return $result;
   }

Can someone help me? I think it's a problem for me because of Pascal syntax of PHP, it seems correct!

marcov:
What is exactly different?

xinyiman:
  KeyBytes[0] := PKV_GetKeyByte(Seed, 24, 3, 200);
  KeyBytes[1] := PKV_GetKeyByte(Seed, 10, 0, 56);
  KeyBytes[2] := PKV_GetKeyByte(Seed, 1, 2, 91);
  KeyBytes[3] := PKV_GetKeyByte(Seed, 7, 1, 100);

Try running the following values, Seed = 1001

Marc:
What values do you get and what do you expect ?

Not everyone is able to run the php code

xinyiman:
Pascal:
 
 a           b            Seed shr a
 24         0                     0
 10         0                     0
 1           2                   244
 7           1                     7


Php:

 a           b            $Seed >> $a
 24         0                     0
 10         0                     0
 1           2                   500
 7           1                     7

Navigation

[0] Message Index

[#] Next page

Go to full version