Auth Crypto - stackoverflow exception? C_C

02/01/2013 17:43 Super Aids#1
Ripped the auth crypto from albetros and when it's creating the keys then I get a overflow exception.

Code:
			CryptKey1 = new byte[0x100];
			CryptKey2 = new byte[0x100];
			byte i_key1 = 0x9D;
			byte i_key2 = 0x62;
			for (int i = 0; i < 0x100; i++)
			{
				CryptKey1[i] = i_key1;
				CryptKey2[i] = i_key2;
				i_key1 = (byte)((0x0F + (byte)(i_key1 * 0xFA)) * i_key1 + 0x13);
				i_key2 = (byte)((0x79 - (byte)(i_key2 * 0x5C)) * i_key2 + 0x6D);
			}
Perhaps anyone here that can spot the error?

To be specific it throws it already from the start at:
Code:
i_key1 = (byte)((0x0F + (byte)(i_key1 * 0xFA)) * i_key1 + 0x13);
When i is 0.
02/01/2013 19:05 Lateralus#2
There's nothing in the method that would cause that. Perhaps you're causing a stack overflow on another thread?
02/01/2013 19:08 Super Aids#3
I tried to do this as the first thing in main and it still caused it. And exactly my though... It's really mind bugging me.

And my bad, not stack overflow, just overflow... xD
02/01/2013 19:19 Lateralus#4
It really shouldn't be overflowing based on the arithmetic, but you can try using the unchecked statement/operator. I'm sure there's some option in the compiler to default to truncate if overflow, but I don't know it, because I've never needed to find it.

Code:
unchecked
{
    i_key1 = (byte)((0x0F + (byte)(i_key1 * 0xFA)) * i_key1 + 0x13);
    i_key2 = (byte)((0x79 - (byte)(i_key2 * 0x5C)) * i_key2 + 0x6D);
}
or

Code:
i_key1 = unchecked((byte)((0x0F + (byte)(i_key1 * 0xFA)) * i_key1 + 0x13));
i_key2 = unchecked((byte)((0x79 - (byte)(i_key2 * 0x5C)) * i_key2 + 0x6D));

Edit: "Note that Visual Studio does not turn on overflow checking by default in either release or debug builds. You need to turn on the Check for Arithmetic Overflow setting in the Build Properties for the project - but make sure you have the Debug configuration selected when you do this."
02/01/2013 19:58 Super Aids#5
I'm not using Visual Studio though. I'm using Sharpdevelop, but will try that thanks.

#Edit got it working by turning that off and it caused problems with all my cryptos XD

This can be closed now... Finally!! XD
02/01/2013 21:36 KraHen#6
Try using Int32 and Byte.
02/01/2013 21:57 Super Aids#7
Already got it fixed bro.
02/01/2013 22:05 CptSky#8
Quote:
Originally Posted by KraHen View Post
Try using Int32 and Byte.
What's the difference ? byte and int are aliases of Byte and Int32. They result in the same IL code.