Mar 16, 2012 at 8:01pm UTC
I'm trying to run a crypto with some data inside it and i cant seem to get it to work correctly.
2b 00 01 00 70 af 8d 6a 00 65 66 71 00 00 00 00 00 67 00 2d 15 0d 15 08 0c 37 14 1b 0f 0d 00 00 00 00 00 00 00 00 00 00 00 00 00
I run this Data up top thru this function and get this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
void CCrypt::DeCryptPacket( CPacket* pak )
{
// Removing the Header..
pak->Buffer.erase( pak->Buffer.begin(),pak->Buffer.begin()+4 );
// check data correctness
size_t decyptbufSize = pak->Buffer.size();
if ( decyptbufSize < 4 )
return ;
const char unknown_key[] = "qmfaktnpgjs" ;
unsigned char unknown_key2[sizeof (unknown_key)];
std::copy(unknown_key, unknown_key + sizeof (unknown_key), unknown_key2);
if ( decyptbufSize < 4 )
return ;
for (unsigned i = 0; i < pak->Buffer.size(); i++)
{
if ( pak->Buffer[i] != 0)
{
pak->Buffer[ i ] = unknown_key2[i % 0xB] ^ pak->Buffer[i];
}
}
}
My answer i get is this..
01 c2 eb 0b 00 11 08 01 00 00 00 00 00 01 00 46 61 63 65 6f 66 44 65 76 69 6c 00 00 00 00 00 00 00 00 00 00 00 00 00
Now when i try to run this top data thru this function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
void CCrypt::EnCryptPacket( CPacket* pak )
{
size_t encryptbufSize = pak->Buffer.size();
if ( encryptbufSize < 4 )
return ;
const char unknown_key[] = "qmfaktnpgjs" ;
unsigned char unknown_key2[sizeof (unknown_key)];
std::copy(unknown_key, unknown_key + sizeof (unknown_key), unknown_key2);
if ( encryptbufSize < 4 )
return ;
// perform XOR encrypting
pak->Buffer[ 0 ] = pak->Buffer.size() & 0xFF;
pak->Buffer[ 1 ] = ( pak->Buffer.size() & 0xFF00 ) >> 8;
pak->Buffer[ 2 ] = 0x01;
pak->Buffer[ 3 ] = 0x00;
for (unsigned i = 4; i < pak->Buffer.size(); i++)
{
if ( pak->Buffer[i] != 0)
{
pak->Buffer[ i ] = unknown_key2[i % 0x0B] ^ pak->Buffer[i];
}
}
}
I get this as a answer
2b 00 01 00 6a b6 85 7b 00 7b 7b 70 00 00 00 00 00 6f 00 21 0b 10 14 02 00 25 0e 02 07 1c 00 00 00 00 00 00 00 00 00 00 00 00 00
When really i should be getting this as a answer
2b 00 01 00 70 af 8d 6a 00 65 66 71 00 00 00 00 00 67 00 2d 15 0d 15 08 0c 37 14 1b 0f 0d 00 00 00 00 00 00 00 00 00 00 00 00 00
Does anyone know why in the encrypt function that its not working corretly (loop?)
edit: please note that in another function before hand im adding 4 bytes in front of that buffer.
Last edited on Mar 16, 2012 at 8:04pm UTC
Mar 16, 2012 at 8:18pm UTC
Hi
what does
pak->Buffer.size();
return in the following loop, is it a number small or equal to 4 ??
1 2 3 4 5 6 7
for (unsigned i = 4; i < pak->Buffer.size(); i++)
{
if ( pak->Buffer[i] != 0)
{
pak->Buffer[ i ] = unknown_key2[i % 0x0B] ^ pak->Buffer[i];
}
}
Edit:: could you post the structure of CPacket ?
Last edited on Mar 16, 2012 at 8:20pm UTC
Mar 19, 2012 at 9:17am UTC
Hi
Run your programm in debug mode and try to find your bugs and errors
, if you cant debug, provide me all your code( including the appication files) as zip file I will try to do it for you.
Mar 20, 2012 at 11:00am UTC
Hi
I dont have MS VS Studio, I may try to import the project into Eclipse and try to find the problem with GCC, but I need some time for that, currently I am just busy.
Mar 20, 2012 at 1:40pm UTC
I believe the problem is with the loop.
for (unsigned i = 4; i < pak->Buffer.size(); i++)
Where i = 4
Your then xoring the array on the 4th
4 % 0x0b = answer. Instead it being 0 % 0x0b = answer..
Only thing i can think of is xor the array before i add in the xor header. But im alittle confused into getting that to work correctly.
Should i just store the header in a differnt pointer then point that data to the other vector and just insert that into the vector. Only problem is that i have to insert it to the front of the vector and vectors dont like data to be reinserted to the front messing up the eliment
Last edited on Mar 20, 2012 at 1:42pm UTC
Mar 20, 2012 at 4:02pm UTC
by the way. which algorithm do you use, the name of algorithm that you use for encrytion and decryption.
Mar 20, 2012 at 5:53pm UTC
None its just a custom algorithm. You should have no problems copy and pasteing it to Eclipse.
Mar 21, 2012 at 9:08pm UTC
Hi
I have just import your code into eclipse, there is no problem with the loop itself, however there is a problem with the algorithm itself.
Is it your own algorithm ? I think I need to analyse your algorithm for it's stability and correctness.
Mar 22, 2012 at 6:56pm UTC
Ya its just a custom algorithm. The stability should be fine but i have no idea why correctness sucks.
If its able to decrypt one way it shouldnt have a problem encrypting another way.