I'm trying to write a script which will show the IP of an Emule user based on the user ID entered. The format for the IP decoding is as follows. This is straight from the coders of Emule:
ID = A + B256 + C2562 + D*2563
Having the ID you need to extract A, B, C, D using cartesian division of polynoms (int |x| means the non decimal part of x):
D = int |ID / 2563 |
C = int | (ID - D2563) / 2562 |
B = int | (ID - D2563 - C2562) / 256 |
A = ID - D2563 - C2562 - B256
Now here is my script's main part:
<?php
if (isset($HTTP_POST_VARS['id'])) {
$id = $HTTP_POST_VARS['id'];
$D = $id / (256^3);
$C = ($id - ($D*(256^3))) / (256^2);
$B = ($id - ($D*(256^3)) - ($C*(256^2))) / 256;
$A = ($id - ($D*(256^3)) - ($C*(256^2)) - ($B*256));
echo("The IP is: <br><br>" .$A. "<br>" .$B. "<br>" .$C. "<br>" .$D);
}
?>
Here is what it spits out when I enter the number 1131554628:
The IP is:
4368936.7876448
The first three numbers are 0 because the calculations are using floating point numbers instead of integers. What's driving me crazy is that last number. Remember that it calculates the last number first (the last number is D, the first calculation) and D is not tampered by anything floating point errors. 1131554628 divided by (2563) is not some huge number, it's 67.446 (which would turn into 67 if done properly).
Any help would be very much appreciated.
PS.
Is there any way to force PHP to use integers instead of floating point, or at least force some truncation?