1

My webhost reports that PHP_INT_MAX is 2147483647, i.e. it's a 32-bit environment. I'm trying to convert a couple of mathematical operations that currently works in a 64-bit environment, so that they also work in the 32-bit environment.

$id = '76561197996545192';
$temp = '';
for ($i = 0; $i < 8; $i++)
{
    $temp .= chr($id & 0xFF);
    $id >>= 8;
}
$result= md5('BE' . $temp);
echo $result;

The above yields de46c6d30bfa6e097fca82f63c2f4f4c in the 32-bit environment, but it should actually yield cd97cc68c1038b485b081ba2aa3ea6fa (which it currently does in the 64-bit environment). I'm guessing that the bitshift operator is causing the mismatch, but I'm not sure (I'm not a php-expert, nor a mathematician, and I'm not the author of the original code :)

BCMath is installed in the 32-bit environment, and there may be other frameworks installed as well (I can check the phpinfo if needed).

How would I go about fixing this? Is it possible?

// Linus

Edit: Yes, I know the code looks weird, but it is working exactly as intended in a 64-bit environment.

Linus Proxy
  • 525
  • 1
  • 5
  • 21

1 Answers1

1

It seems to me that the bitwise operations does not really do what you expect them to do since $id is a string. I understand that it can not be an integer since it would be too big for the 32-bit system. Maybe what you were trying to do is to handle the last 3 characters of $id and make them into an integer? This would be the code for that:

$id = '76561197996545192';
$temp = '';
for ($i = 0; $i < 8; $i++) {
    $tnbr = intval(substr($id, -3));
    $char = chr($tnbr & 0xFF); // Is the bitwise to make them valid chars? Maybe skip that part?
    $temp .= $char;
    $id = substr($id, 0, strlen($id) - 3);
}

$result = md5('BE' . $temp);
echo $result;

This gives me the result of 98b0f4cc942bfe4a22dd7877ae3e9f06.

I am not sure what the purpose of this mathematical algorithm is, but maybe I don't need to :)

Good luck! /Wille

willeeklund
  • 166
  • 1
  • 7
  • You might be correct, I need to double check this. The question is then how to declare $id as a "bigger" int without actually having such a data type available. Can BCMath be used for that? – Linus Proxy Nov 03 '14 at 15:09