Question about sending packets with usigned variables

12/28/2010 08:53 tkblackbelt#1
Ok so I started making a proxy in java and Have got up to receiving the password seed. But I've run into a problem java doesn't have unsigned variables so I had to edit the auth cryption to use short values. I can get the password seed perfectly its just forwarding it to the client I'm not sure how to do because the socket doesn't send a short array. I try sending the origional byte array but got no response from the client. If anyone can give me some pointers on how to do this I would appreciate it thanks.

when the byte is over 128 it wraps around to negative numbers

the byte array look like -59 72 105 18 32 -47 47 -103
the short array looks like 197 72 105 18 41 163 18 61
12/28/2010 09:14 ChingChong23#2
thats why you go byte & 0xff

take a look through here: [Only registered and activated users can see links. Click Here To Register...]
12/28/2010 09:50 tkblackbelt#3
Quote:
Originally Posted by ChingChong23 View Post
thats why you go byte & 0xff

take a look through here: [Only registered and activated users can see links. Click Here To Register...]
Thanks I will definetly take a look through that source. I'n my auth cryption file I changed everything to use short variables as shown below

public void DecryptBackwards(short[] buffer)
{
for (int i = 0; i < buffer.length; i++)
{

buffer[i] ^= (short)(_cryptKey2[_decryptCounter.getKey2()] ^ _cryptKey1[_decryptCounter.getKey1()]) & 0xff;
buffer[i] = (short) ((short)(buffer[i] >> 4 | buffer[i] << 4) & 0xff);
buffer[i] ^= (short)0xAB;
_decryptCounter.Increment();
}
}

And this is what I used to convert bytearray to short array
public static short[] byteArrayToShortArray(byte[] buffer){

short[] array = new short[buffer.length];
for(short i = 0; i < buffer.length;i++){
array[i] = (short) (buffer[i] & 0xff);
}
return array;
}

This works perfectly to get the value of the auth packet, but I'm woundering how to forward the short array to the client, if I send the signed byte array with the negative values and such will the client still be able to use the bytes or do they have to be in the unsigned form?
12/28/2010 14:58 IAmHawtness#4
It shouldn't really matter in hexadecimal, unless of course you're using these values for something. And really, Java doesn't have unsigned variables? That sucks
12/28/2010 18:19 .Kinshi#5
Another reason why Java is a horrible language :P


You can take a look at this:

[Only registered and activated users can see links. Click Here To Register...]
12/28/2010 21:33 IAmHawtness#6
Quote:
Originally Posted by .Kinshi View Post
Edit: Sorry for double post, stupid internet >.<
Edit -> press "Delete" -> tick "Delete Message" -> press "Delete this Message"
12/28/2010 23:05 shitboi#7
You dont really need to change the type from byte to short (though i have made the same mistake before). Seeing a different decimal or hexadecimal value does not matter much. What it REALLY matters is that what represents the data in bits.
Java does not have unsigned. therefore the largest positive number you can go is 127, while in other languages that supports signed byte, the largest you see is 255.

127 (java) in bits is 1111 1111 (leading bit is interpreted as sign bit)
255(c++) in bits is also 1111 1111

Since encryption and decryption takes place on a bit level, all you need to care about is that, the bits are the same. You can care less about how your programming language interprets these bits.

good luck