• Welcome to Valhalla Legends Archive.
 

PHP BNLSChecksum() problems

Started by R.a.B.B.i.T, April 23, 2005, 10:06 PM

Previous topic - Next topic

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)

<?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));	}?>


Any ideas?

raylu

Explain the code?

Why add 00000000 and what doe CRC32 do?
Pie?

MyndFyre

Quote from: raylu on April 29, 2005, 09:06 PM
Explain the code?

Why add 00000000 and what doe CRC32 do?

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

tA-Kane

#3
Take another look at his code. It is equivalent to:
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


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 &
Macintosh programmer and enthusiast.
Battle.net Bot Programming: http://www.bash.org/?240059
I can write programs. Can you right them?

http://www.clan-mac.com
http://www.eve-online.com

MyndFyre

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:


<?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;	}?>



If you do something like that, it should probably become obvious where the problem is.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

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.

Banana fanna fo fanna


<?phpfunction BNLSChecksum($password, $servercode){$val = "0000000" . $servercode;return CRC32($password . substr($val, strlen($val) - 8));}


'.' is the string concat operator.

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:
<?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;	}?>


Joe[x86]

Out of curiosity, what will this be used for?
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

R.a.B.B.i.T

A PHP Bot (a real one, that is).