Valhalla Legends Forums Archive | Battle.net Bot Development | PHP BNLSChecksum() problems

AuthorMessageTime
R.a.B.B.i.T
Not to say that it doesn't work, it does, but it doesn't give the desired return.

VB6: BNLSChecksum("test", 1) = 520521760
PHP: BNLSChecksum("test", 1) = -2082672713
PHP: BNLSChecksum2("test", 1) = -186917087

[update] PHP: BNLSChecksum2("Sample", 0x123ABCD) == 212270949(!=318631304)
[update] PHP: BNLSChecksum2("Sample", 0x123ABCD) == -810156055 (!=318631304)

[code]<?php

function BNLSChecksum($password, $servercode)
{
$val = "0000000" + $servercode;
return CRC32($password + substr($val, strlen($val) - 8));
}

function BNLSChecksum2($password, $servercode)
{
$val = "0000000" & $servercode;
return CRC32($password & substr($val, strlen($val) - 8));
}

?>[/code]

Any ideas?
April 24, 2005, 3:06 AM
raylu
Explain the code?

Why add 00000000 and what doe CRC32 do?
April 30, 2005, 2:06 AM
Myndfyr
[quote author=raylu link=topic=11375.msg110488#msg110488 date=1114826802]
Explain the code?

Why add 00000000 and what doe CRC32 do?
[/quote]

This is the code for the BNLS_AUTHORIZE_PROOF message (documented http://www.valhallalegends.com/yoni/bnlsprotocolspec.txt).  CRC32 is a standard algorithm -- the 32-bit cyclic redundancy check.

rabbit: I think you're padding 8 '0' characters, whereas you're only supposed to pad *up to* 8 total characters.  So if your hex value is 6 characters, you add two 0s to it.
April 30, 2005, 3:40 AM
tA-Kane
Take another look at his code. It is equivalent to:
[code]Function BNLSChecksum(Password As String, ServerCode As Integer) As Integer
  Dim Var As String
  Var = "0000000" & Hex(ServerCode)
  Return CRC32(Password & Mid(Var, Len(Var)-8))
End Sub[/code]

I don't see a difference between BNLSChecksum and BNLSChecksum2 in that PHP script, though.

Remember that BNLS expects the hexadecimal digits to be in UPPER CASE. I do not see you making sure of such.


Edit: nevermind, found the difference... + vs &
April 30, 2005, 6:17 AM
Myndfyr
You're right Kane, I missed that.

rabbit: it might be useful for you to break out subexpressions and write them to output somewhere that you can evaluate everything to make sure you're doing it right.  I might suggest this:

[code]
<?php

function BNLSChecksum($password, $servercode)
{
$val = "0000000" + $servercode;
// Print $val here.
$len = strlen($val); // is that the right declaration?  I can never remember these variable $ symbols.
// Print $len
$part = substr($val, $len - 8);
// Print $part
$crcexp = $password + $part;
// Print $crcexp
$crcval = CRC32($crcexp);
// Print $crcval
return $crcval;
}
?>
[/code]

If you do something like that, it should probably become obvious where the problem is.
April 30, 2005, 7:34 AM
R.a.B.B.i.T
The 8 "0"'s came from my port from the VB function.  I'll break it up like you suggested, and I'll see what happens.
May 1, 2005, 2:03 PM
St0rm.iD
[code]
<?php
function BNLSChecksum($password, $servercode)
{
$val = "0000000" . $servercode;
return CRC32($password . substr($val, strlen($val) - 8));
}
[/code]

'.' is the string concat operator.
May 1, 2005, 2:23 PM
R.a.B.B.i.T
Yes, by stepping through I found a few problems:
1. You must use dechex() on the $servercode or else it will insert the dec value (which is wrong)
2. You must convert the new $servercode to upper case
3. You must use '.' (as Banana said), not '+'
That's all I can remember for now, here's the final, working code:
[code]<?php

function ucase($str)
{
$lc = array('a', 'b', 'c', 'd', 'e', 'f');
$uc = array('A', 'B', 'C', 'D', 'E', 'F');
$final = str_replace($lc, $uc, $str);
return $final;
}

function BNLSChecksum($password, $servercode)
{
$uc_sc = ucase(dechex($servercode));
// echo '$uc_sc = ' . $uc_sc . "<BR>\r\n";

$val = "0000000" . $uc_sc;
// echo '$val = ' . $val . "<BR>\r\n";

$len = strlen($val);
// echo '$len = ' . $len . "<BR>\r\n";

$part = substr($val, $len - 8);
// echo '$part = ' . $part . "<BR>\r\n";

$crcexp = $password . $part;
// echo '$crcexp = ' . $crcexp . "<BR>\r\n";

$crcval = CRC32($crcexp);
// echo '$crcval = ' . $crcval . "<BR>\r\n";

return $crcval;
}
?>[/code]
May 1, 2005, 3:58 PM
JoeTheOdd
Out of curiosity, what will this be used for?
May 2, 2005, 12:50 AM
R.a.B.B.i.T
A PHP Bot (a real one, that is).
May 2, 2005, 4:31 AM

Search