[Release]HabboRC4 (Latest SWF release I think) [C++

Adil

DevBest CEO
May 28, 2011
1,276
714
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!
 

Users who are viewing this thread

Top