Fastest method to generate key3, key4 (standerd conquer encryption)

07/03/2008 01:13 InfamousNoone#1
Because I'll probably never need this again, I might as well demonstrate how exactly to generate key3 and key4 faster than coemu's gay slow method.

You'll actually have to have some knowledge of coding to be able to convert this to C# to use in your source (because most sources are in C#... I wonder why...:rolleyes:).

Note to disclaimer: This probably isn't the "fastest" method, but it's the fastest method I've developed.

Code:
#define sqr(x) x * x
#define ptr(t, i, v) (((t*)v) + i)
void SetKeys(DWORD* inKey1, DWORD* inKey2)
{
	DWORD dwKey1 = ((*inKey1 + *inKey2) ^ 0x4321) ^ *inKey1;
	DWORD dwKey2 = sqr(*inKey1);
	Key3 = new unsigned char[256];
	Key4 = new unsigned char[256];
	for (unsigned char i = 0; i < 64; i++)
	{
		*ptr(DWORD, i, Key3) = dwKey1 ^ *ptr(DWORD, i, Key1);
		*ptr(DWORD, i, Key4) = dwKey2 ^ *ptr(DWORD, i, Key2);
	}
}
07/03/2008 08:47 leavemealone#2
I havn't tested it but i just typed this up for C# users may work.

Code:
private unsafe uint sqr(uint x)
{
	uint Result = x * x;
        return Result;
}
private unsafe uint ptr(byte i, uint Key)
{
	uint Result = *(((uint*)Key) + i);
        return Result;
}
private unsafe void SetKeys(uint* inKey1, uint* inKey2)
{
	uint dwKey1 = ((*inKey1 + *inKey2) ^ 0x4321) ^ *inKey1;
        uint dwKey2 = sqr(*inKey1);
        Key3 = new byte[256];
        Key4 = new byte[256];
        for (byte i = 0; i < 64; i++)
        {
        	uint Result1 = ptr(i, Convert.ToUInt32(Key3));
        	Result1 = dwKey1 ^ ptr(i, Convert.ToUInt32(Key1));
        	uint Result2 = ptr(i, Convert.ToUInt32(Key4));
		Result1 = dwKey2 ^ ptr(i, Convert.ToUInt32(Key2));
	}
}
07/03/2008 13:49 tanelipe#3
Code:
public unsafe void SetKeys(uint* inKey1, uint* inKey2)
        {
            uint dwKey1 = ((*inKey1 + *inKey2) ^ 0x4321) ^ *inKey1;
            uint dwKey2 = (uint)(dwKey1 * dwKey1);
            Key3 = new byte[256];
            Key4 = new byte[256];
            fixed (void* uKey1 = ConquerKeys.Key1, uKey3 = Key3,
                         uKey2 = ConquerKeys.Key2, uKey4 = Key4)
            {
                for (sbyte i = 0; i < 64; i++)
                {
                    *(((uint*)uKey3) + i) = dwKey1 ^ *(((uint*)uKey1) + i);
                    *(((uint*)uKey4) + i) = dwKey2 ^ *(((uint*)uKey2) + i);
                }
            }
        }
ConquerKeys.Key1 = KeyOne
ConquerKeys.Key2 = KeyTwo

Note: It's your own work infamous.
07/08/2008 23:57 Hawk2006#4
What are the keys for?
07/09/2008 05:32 InfamousNoone#5
They're used in the encryption of packets.