• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Habbo Encoding/Decoding (Cryptography) (r63)

Banned
Banned
Joined
Aug 13, 2012
Messages
23
Reaction score
2
Series Part 1 of 3 >> Continue
_______________________________

Um so I did this little release to help people understand the encoding and decoding of bytes in a packet for the Habbo Hotel emulation protocols. Now this is stretching to the core of how this works so I did it in a language most will understand... PHP (better love me for that). Once you have grasped the concepts behind how each method works you will then be able to understand how the files such as 'ByteUtil.cs', 'HexEncoding.cs' and 'ByteEncoding.cs' work.

It's fairly simple and you will be like 'oo-hh!' once you understand how strings, booleans and integers can be converted to and from base64, hexadecimal and binary values. This is in my opinion the hardest thing to grasp when it comes to Habbo Hotel emulation although once you are able to understand this and write your own equivalent methods, all you need to do is figure out the structure and voila you have an emulator.

The release focuses only on encoding and not decoding. To decode, simply reverse the methods at their core.

Important

Do not confuse this with something you can use live. It's a) done in PHP and b) does not use any native methods therefore it's quite inefficient as it's only supposed to show you the meat behind the native method to help you better understand everything.

Habbo uses base64 (among other encoding) which at it's core works like this:

string -> encodes ascii (depending on type) -> 8 bit binary values -> joined together into a string containing 'x' amount of bytes -> groups into 6 bits since base64 has a maximum of 64 values -> converted to integers -> used to map to encoded values.

Once you understand how the core works you can go about creating your own methods to handle base64 encoding and decoding (among other things).

This will only help you get the decoded packet, not give you the packet id and blah blah blah. This release/tutorial is here to help you decode the Habbo packets.

Other Important Things

Um in case you guys don't understand what binary being base 2 and hexadecimal being base 16 means then hear this out.

Normally, what you are taught in school is called base 10 counting. Meaning the numerical system goes from 0 to 9 and then 10 to 19. If we dissect any number (19 for example) you need to think of it like this. The number 19 is '1' - '9' meaning one set of 10 and 9, totalling 19. The same methodology of thinking is applied to binary base 2 and hexadecimal base 16.

To represent these in your program, it all depends on the language. For C++ to represent a hexadecimal number it must begin with the prefix '0x'. For binary it must begin with the prefix '0b'. Decimal numbers can be represented as standalone numbers. Make sure you are aware of this, all depends on the language you are programming!

Release #1 (Encoding/Decoding Basics)

To convert a decimal value to a binary or hexadecimal value take a look at this:

PHP:
/**
 * Converts a decimal value to a binary string.
 *
 * @param	int		$decimal		The decimal value to be converted.
 *
 * @return	string
 */
function dec_to_bin($decimal)
{
	$bin_map = array(
	0		=>		0,
	1		=>		1
	);
	
	$number = $decimal;
	$binary = '';
	
	while ($decimal > 0)
	{
		$bit = $decimal % 2;
		
		// Appends the binary string in reverse order.
		$binary .= $bin_map[$bit];
		$decimal /= 2;
		
		// Evens the decimal value if it was an odd decimal value (1, 3, 5, 7, 9, etc.).
		if ($bit == 1)
		{
			$decimal -= 0.5;
		}
	}
	
	// Reverses the binary string back to it's original order.
	$binary = strrev($binary);
	
	return $binary;
}

/**
 * Converts a decimal value to a hexadecimal string.
 *
 * @param	int		$decimal		The decimal value to be converted.
 *
 * @return	string
 */
function dec_to_hex($decimal)
{
	// Maps numerical values to hexadecimal values.
	$hex_map = array(
	0		=>		0,
	1		=>		1,
	2		=>		2,
	3		=>		3,
	4		=>		4,
	5		=>		5,
	6		=>		6,
	7		=>		7,
	8		=>		8,
	9		=>		9,
	10		=>		'A',
	11		=>		'B',
	12		=>		'C',
	13		=>		'D',
	14		=>		'E',
	15		=>		'F',
	);
	
	// Copies decimal value.
	//$number = $decimal;
	// '0x' is the typical prefix or a trailing 'h'.
	$hex = '0x';
	// Binary base.
	$bin_base = 2;
	// Hexadecimal base.
	$hex_base = 16;
	// Number to group the bits into is log(hex base, bin base).
	$group = log($hex_base, $bin_base);
	
	// Converts the decimal string into binary.
	$binary = dec_to_bin($decimal);
	// Splits the binary string into an array for each bit.
	$bit_array = str_split($binary, $group);
	$new_binary = '';
	
	// Padds the binary string so that it is divisable by the $group variable. This is very important.
	foreach ($bit_array as $key => $value)
	{
		$modular = strlen($value) % $group;
		
		if ($modular != 0)
		{
			for ($i = 0; $i < ($group - $modular); $i++)
			{
				$new_binary = 0 . $new_binary;
			}
			
			$new_binary .= $value;
		}
		else
		{
			$new_binary .= $value;
		}
	}
	
	$fourbit_array = str_split($new_binary, $group);
	//$size = sizeof($fourbit_array);
	$j = 1;
	
	// Loops through the half a byte array and assigns each half a byte a hexadecimal value based on
	// their numerical value and appends it to the hexadecimal string variable.
	foreach ($fourbit_array as $key => $value)
	{
		$value = strrev($value);
		$new_array = str_split($value);
		$i = 1;
		$index = 0;
		
		foreach ($new_array as $bit)
		{
			$index += $bit * $i;
			
			// Increases base multiplier.
			$i *= $bin_base;
		}
		
		$hex .= $hex_map[$index];
		
		$j++;
	}
	
	return $hex;
}

So in turn if you want to try encoding a decimal value to a hexadecimal value, try this:

PHP:
print dec_to_hex(255); // Prints '0xFF' which is equivalent to the numerical value of 255.

I found converting to ascii pretty straight forward so no need on a snippet for that. But in case you did not know, once it's encoded to ascii you can grab the corresponding decimal values assigned to the letter enabling you to apply these methods.

In practice, your methods will be quite a bit shorter as the language you choose will have native methods to handle all of this. I am just showing you how they work so that when you type them or copy them from google you know how it works as this will come in handy if you plan to have a successful emulator.

Release #2 (Bitwise Operations)

This is very important for handling the encoding and decoding of the Habbo packet structure as you will need to shuffle bits to 're-assemble' the packet (so to speak). Make sure you are familiar with that or else you will have some problems. It's pretty straight forward, if you need help just google the Bitwise operators. Some examples of those are the & (and), | (or), ^ (xor), << (shuffle left), >> (shuffle right).
 
Last edited:
Junior Spellweaver
Joined
Feb 4, 2012
Messages
114
Reaction score
38
Re: Understanding Habbo Encoding

1/100 people who read this will understand, lol.
 
topkek amirite??
Joined
May 16, 2009
Messages
751
Reaction score
696
Re: Understanding Habbo Encoding

1/100 people who read this will understand, lol.
The point of the post was to remedy the fact that some people don't understand the habbo encoding.

Thanks for that epic explanation!

Edit: 500th post ;D
 
Banned
Banned
Joined
Aug 13, 2012
Messages
23
Reaction score
2
Re: Understanding Habbo Encoding

The point of the post was to remedy the fact that some people don't understand the habbo encoding.

It is fairly easy to handle the new cryptography in place on the latest version of Habbo. You just need to understand everything and it starts from the core. This is just a brief thread overviewing some of the basics in part of the base 64 encoding/decoding. To create your own methods you need to be familiar with these concepts.

I looked at Uber and Butterfly and much can be improved from both of those. It starts with the base, not making an attack on Ion but much can be improved on it just as much can be learned from it. Especially in the areas of decoding and encoding the packets.
 
Banned
Banned
Joined
Aug 13, 2012
Messages
23
Reaction score
2
Re: Habbo Encoding (New Cryptography)

Why are we still working with the old protocol?
Habbo used custom encoding methods for that..

I think you do not understand the value of the thread. For any protocol (including the latest one) you will need to figure out proper byte and bit offsets, as well as any custom encoding that Habbo applies. If you do not understand the basics that are within my thread then it will not be possible for you to develop packet encoding and decoding methods as they all contain some form of string manipulation, in particular: binary, octal, hexadecimal and/or base64 encoding/decoding. This thread helps explain all of these concepts so that you are able to apply them in your packet manipulation methods, whether it be encoding or decoding.

This thread helps you understand how bitmasks and offsets can work at their core. You of course need to be familiar with all of the Bitwise operators and familiar with what the Habbo offsets are, but that is an entirely new problem.
 
Joined
Jun 23, 2010
Messages
2,324
Reaction score
2,195
Re: Habbo Encoding (General Cryptography)

Habbo uses base64 (among other encoding) which at it's core works like this:

used*

This will only help you get the decoded packet, not give you the packet id and blah blah blah. This release/tutorial is here to help you decode the Habbo packets.

What tutorial? The only thing where you writing about is how important and what this thread is all about..

Normally, what you are taught in school is called base 10 counting. Meaning the numerical system goes from 0 to 9 and then 10 to 19. If we dissect any number (19 for example) you need to think of it like this. The number 19 is '1' - '9' meaning one set of 10 and 9, totalling 19. The same methodology of thinking is applied to binary base 2 and hexadecimal base 16.

although base 2 (binary) counting works kind of diffrent then base 10 counting

Binary - base 10
Code:
00000000 = 0
00000001 = 1
00000010 = 2
00000011 = 3
00000100 = 4
00000101 = 5
00000110 = 6
00000111 = 7
00001000 = 8
00001001 = 9

That will mean that "19" is "00000001 00001001" in binary or should it be "00010011"?
As the first will display 1, 9 and then second will display 19 directly.

Note: Those are non ancii chars!

This is very important for handling the encoding and decoding of the Habbo packet structure as you will need to shuffle bits to 're-assemble' the packet (so to speak). Make sure you are familiar with that or else you will have some problems. It's pretty straight forward, if you need help just google the Bitwise operators. Some examples of those are the & (and), | (or), ^ (xor), << (shuffle left), >> (shuffle right).

I don't see any release/tutorial in there, still the talk that's it's important and gives some examples of some operaters.
Saying "just google the bitwise operators" you could atleast explain in here what they are doing.



But, maybe this is just a to big topic to make a tutorial about.
As this thread has a lack of depth in serveal points.
 
topkek amirite??
Joined
May 16, 2009
Messages
751
Reaction score
696
Re: Habbo Encoding (General Cryptography)

This thread should be stickied or something, it contains tonnes of important information (IMO)
 
Banned
Banned
Joined
Aug 13, 2012
Messages
23
Reaction score
2
Re: Habbo Encoding (General Cryptography)

What tutorial? The only thing where you writing about is how important and what this thread is all about..
I don't see any release/tutorial in there, still the talk that's it's important and gives some examples of some operaters.
Saying "just google the bitwise operators" you could atleast explain in here what they are doing.



But, maybe this is just a to big topic to make a tutorial about.
As this thread has a lack of depth in serveal points.

It is probably more of a tutorial than a release but I felt it was important to be posted.

although base 2 (binary) counting works kind of diffrent then base 10 counting

Binary - base 10
Code:
00000000 = 0
00000001 = 1
00000010 = 2
00000011 = 3
00000100 = 4
00000101 = 5
00000110 = 6
00000111 = 7
00001000 = 8
00001001 = 9

That will mean that "19" is "00000001 00001001" in binary or should it be "00010011"?
As the first will display 1, 9 and then second will display 19 directly.

Note: Those are non ancii chars!

In your example you are showing two bytes, one with a value of 1 and another with a value of 9. It will be of values 1 and 9 but not display 19. The number '19' would be represented as the values 49 and 57 to correspond to the ascii characters. I see you mentioned that but yea, just clarifying.

Binary counts different yes, seeing as it's base two we can represent decimal numbers like this. '9' in binary would be '1001'. If we dissect this we see that it is: '1' set of 8, '0' sets of 4, '0' sets of 2, '1' set of 1. It's a similar methodology used for all the counting systems they just need to understand the difference between counting base 10 and base 2.

I can probably add more information about this, I just did not think it would be needed if I mentioned they are the same counting style just different base number.
 
Last edited:
Back
Top