Skip to content

Instantly share code, notes, and snippets.

@marcaddeo
Created January 23, 2012 23:17
Show Gist options
  • Save marcaddeo/1666305 to your computer and use it in GitHub Desktop.
Save marcaddeo/1666305 to your computer and use it in GitHub Desktop.
Encryption methods
#include "Crypto.h"
#include "keys.h"
Crypto::Crypto( void ) :
m_useNewKeys(false)
, m_localCounter()
, m_remoteCounter()
{}
Crypto::~Crypto( void )
{
}
void Crypto::incoming( char *packet, size_t size )
{
for ( size_t i = 0; i < size; i++ )
{
int num = this->m_remoteCounter.first;
packet[i] = ( ( packet[i] ^ Key1[num] ) ^ Key2[this->m_remoteCounter.second] );
this->m_remoteCounter++;
}
}
void Crypto::outgoing( char *packet, size_t size )
{
hexdump( ( void * )packet, 52);
for ( size_t i = 0; i < size; i++ )
{
int num = this->m_localCounter.first;
if ( this->m_useNewKeys )
packet[i] = ( ( packet[i] ^ Key3[num] ) ^ Key4[this->m_localCounter.second] );
else
packet[i] = ( ( packet[i] ^ Key1[num] ) ^ Key2[this->m_localCounter.second] );
this->m_localCounter++;
}
}
void Crypto::generate_keys( CPacket packet )
{
int seed, seed2;
memcpy( ( void * )&seed, ( void * )( packet.data + 0x04 ), 4 );
seed2 = seed * seed;
for ( int i = 0; i < 256; i += 4 )
{
int *pKey3 = ( int * )&Key3[i];
int *pKey4 = ( int * )&Key4[i];
*pKey3 = *( int * )&Key1[i] ^ *( int * )&seed;
*pKey4 = *( int * )&Key2[i] ^ *( int * )&seed2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment