Skip to content

Instantly share code, notes, and snippets.

@XMPPwocky
Created April 15, 2015 22:47
Show Gist options
  • Save XMPPwocky/87a820f70b4d9813cd22 to your computer and use it in GitHub Desktop.
Save XMPPwocky/87a820f70b4d9813cd22 to your computer and use it in GitHub Desktop.
typedef unsigned long int uint32;
#define FlipBytes32(A) ((((uint32)(A) & 0xff000000) >> 24) | (((uint32)(A) & 0x00ff0000) >> 8) | (((uint32)(A) & 0x0000ff00) << 8) | (((uint32)(A) & 0x000000ff) << 24))
static const unsigned char MungeTable2[] = {0x05, 0x61, 0x7A, 0xED, 0x1B, 0xCA, 0x0D, 0x9B, 0x4A, 0xF1, 0x64, 0xC7, 0xB5, 0x8E, 0xDF, 0xA0 };
void Crypt(char *packet, int length, int z, bool unpack)
{
unsigned int * lbuff = (unsigned int *)packet;
unsigned int ebpc;
int i, count = 0;
int notz = ~z;
if(length < 1) { return; }
length = length >> 2;
while(length--)
{
if(unpack)
ebpc = *lbuff ^ z;
else
ebpc = FlipBytes32(*lbuff ^ notz);
for(i=0;i<4;i++)
*((unsigned char *)(&ebpc) + i) ^= (((MungeTable2[(count + i) & 0x0F] | (i << i)) | i) | 0xA5);
if(unpack)
*lbuff = FlipBytes32(ebpc) ^ notz;
else
*lbuff = ebpc ^ z;
lbuff++;
count++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment