Quantcast
Channel: RaGEZONE - MMO Development Forums
Viewing all articles
Browse latest Browse all 14581

[Release] [C++]RC4 class for Habbo (I think) - Latest rev

$
0
0
Here it is...
Code:

#include <iostream>
#pragma once


// RC4.h
// Contains definitions for functions to be used in RC4.cpp
typedef unsigned char byte;
class RC4
{
public:
RC4(void);

~RC4(void);

void Init(byte tKey[]);

void swap(int,int);

void parse(byte t[]);


private:
int i;
int j;
int table[256];

};

RC4.cpp
Code:

#include "RC4.h"


RC4::RC4(void)
{
}




RC4::~RC4(void)
{
}

void RC4::Init(byte *tKey)
{
int len = sizeof(tKey)/sizeof(byte);
this->i = 0;
while(this->i < 0x100)
{
this->table[this->i] = this->i;
this->i++;
}

this->i=0;
this->j=0;

while(this->i < 0x100)
{
this->j = ((this->j + this->table[this->i]) + (tKey[this->i % len] & 0xff)) % 0x100 ;
this->swap(this->i,this->j);
this->i++;
}

this->i=0;
this->j=0;


}

void RC4::swap(int a, int b)
{
int x = this->table[a];
this->table[a] = this->table[b];
this->table[b] = x;

}

void RC4::parse(byte *k)
{
int x = sizeof(k)/sizeof(byte);
for(int a = 0; a < x; a++)
{
this->i = (this->i+1)%256;
this->j = (this->j + this->table[this->i]) % 256;
this->swap(this->i,this->j);
k[a] = (byte)((k[a] & 0xff) ^ this->table[(this->table[this->i] + this->table[this->j]) % 256]);
}
}

I have not tested it as of yet. It is a direct port of Itachi's Java release.
Sorry for the lack of documentation, this was written quite quickly.

Have fun!

Usage
Code:

RC4 *rc4 = new RC4(); // create the rc4 variable on the heap
rc4->init(byte[] tKey);
rc4->parse(byte[] tKey);


Viewing all articles
Browse latest Browse all 14581

Trending Articles