Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Habbo V1 RC4 Encryption - C#

Developer
Developer
Joined
Dec 11, 2010
Messages
2,955
Reaction score
2,688
Hello,

So I know this is 21 years late but I decided to try and get RC4 working in the very first version of Habbo, since we have the decompiled Habbo shockwave files, this was a task that only took me two days to complete!

Of course the RC4 in V1 can always be bypassed, but it's a cool feature to have regardless!

Screenshots:

zeqnRv7 - Habbo V1 RC4 Encryption - C# - RaGEZONE Forums


How to use:

After you receive VERSIONCHECK, generate a public key (can be anything with letters and numbers) and then send these two packets below:

Code:
player.Send(new EncryptionOnComposer());
player.Send(new SecretKeyComposer(player.Connection.PublicKey));

Translates to

Code:
##ENCRYPTION_ON{13}#
##SECRET_KEY{13}PUBLIC_KEY{13}#

Initialise the RC4 with the decoded public key:

Code:
public void InitialiseEncryption()
{
    if (Encryption != null)
    {
        return;
    }

    Encryption = new RC4();
    Encryption.SetKey(SecretKey.SecretDecode(PublicKey));

    Channel.Pipeline.AddFirst("encryption", new EncryptionDecoder(this.Encryption));
}

And then any incoming packets after this will be enciphered by the client and must be deciphered by the server:

Code:
byte[] payload = new byte[buffer.ReadableBytes];
buffer.ReadBytes(payload);

var messagePayload = StringUtil.GetEncoding().GetString(payload);
var decodedPayload = StringUtil.GetEncoding().GetBytes(this.rc4.Decipher(messagePayload));

var result = Unpooled.Buffer();
result.WriteBytes(decodedPayload);
output.Add(result);

The RC4 and SecretKey classes I've written:

Ported from:





RC4:

Code:
/**
 * Habbo Hotel V1 RC4 class by Quackster (Alex)
 * Written in December 2021
 */

using System;
using System.Globalization;

namespace Euclid.Util.Encryption
{
    public class RC4
    {
        private int i;
        private int k;
        private int j;

        private int[] sbox;
        private int[] skey;

        /// <summary>
        /// Create key, not used, but ported from Habbo V1 RC4 class written in Lingo
        /// </summary>
        public int CreateKey()
        {
            var k = "";
            var random = new Random();
            var i = 0;

            while (i < 4)
            {
                k += int2hex(random.Next(256) - 1);
                i++;
            }

            return Math.Abs(hex2int(k));
        }

        /// <summary>
        /// Initialise the encryption class
        /// </summary>
        /// <param name="myKey"></param>
        public void SetKey(int myKey)
        {
            // Console.WriteLine("New key assigned to RC4: " + myKey);
            
            skey = new int[256];
            sbox = new int[256];

            i = 0;
            k = 0;

            var tempKey = Convert.ToString(myKey);

            while (i <= 255)
            {
                skey[i] = (int)tempKey[i % tempKey.Length];
                sbox[i] = i;
                i = 1 + i;
            }

            i = 0;
            j = 0;

            while (i <= 255)
            {
                j = (j + sbox[i] + skey[i]) % 256;
                k = sbox[i];
                sbox[i] = sbox[j];
                sbox[j] = k;
                i = 1 + i;
            }


            i = 0;
            j = 0;

            //Print(sbox);
            //Print(skey);
        }

        /// <summary>
        /// Recreate the enciphering performed on the client
        /// </summary>
        public string Encipher(string data)
        {
            string cipher = string.Empty;
            int a = 0;

            while (a < data.Length)
            {
                cipher += int2hex(data[a] ^ shift());
                a++;
            }

            return cipher;
        }

        /// <summary>
        /// Decipher incoming packets from client
        /// </summary>
        public string Decipher(string data)
        {
            string cipher = string.Empty;
            int a = 0;

            while (a < data.Length)
            {
                var t = hex2int(data.Substring(a, 2));
                cipher += (char)(t ^ shift());
                a += 2;
            }

            return cipher;
        }

        /// <summary>
        /// Shift RC4 tables
        /// </summary>
        private int shift()
        {
            i = (i + 1) % 256;
            j = (j + sbox[i]) % 256;
            var temp = sbox[i];
            sbox[i] = sbox[j];
            sbox[j] = temp;
            return sbox[(sbox[i] + sbox[j]) % 256];
        }

        /// <summary>
        /// int2hex ported from Lingo
        /// </summary>
        public static string int2hex(int aint)
        {
            var digits = "0123456789ABCDEF";
            var hexstr = "";

            if (aint <= 0)
                hexstr = "00";
            else
            {
                while (aint > 0)
                {
                    var sd = (aint % 16);
                    aint /= 16;
                    hexstr = digits[sd] + hexstr;
                }
            }

            if ((hexstr.Length % 2) == 1)
                hexstr = "0" + hexstr;

            return hexstr;
        }

        /// <summary>
        /// hex2int method used for deciphering
        /// </summary>
        public static int hex2int(string ahex)
        {
            return int.Parse(ahex, NumberStyles.HexNumber);
        }
        
        /// <summary>
        /// Used for debugging tables
        /// </summary>
        private void Print(int[] array)
        {
            foreach (int i in array)
                Console.Write(i + ", ");

            Console.WriteLine();
        }
    }
}

SecretKey:

Code:
/**
 * Habbo Hotel V1 RC4 class by Quackster (Alex)
 * Written in December 2021
 */

namespace Euclid.Util.Encryption
{
    public class SecretKey
    {
        /// <summary>
        /// Decode the secret sent from client
        /// </summary>
        public static int SecretDecode(string key)
        {
            string table = key.Substring(0, key.Length / 2); ;
            string tempKey = key.Substring(key.Length / 2);

            int checkSum = 0;
            int i = 0;

            while (i < tempKey.Length)
            {
                var a = table.IndexOf(tempKey[i]);

                if (a % 2 == 0)
                {
                    a *= 2;
                }

                if (i % 3 == 0)
                {
                    a *= 3;
                }

                if (a < 0)
                {
                    a = (tempKey.Length % 2);
                }

                checkSum += a;
                i++;
            }

            return checkSum;
        }
    }
}
 

Attachments

You must be registered for see attachments list
Last edited:
Experienced Elementalist
Joined
Jan 18, 2008
Messages
228
Reaction score
12
Well.. i'm a oldskooler, so i guess i will response to this. Alex u did a great job again. handfull for guys who loves the old retro's. I miss those days :)

And happy new year buddy, and for everyone who knows me.

Smell ya later.

Back when we were all setting up Debbo and Holograph as kids behind a slow pc with MSN messenger on the background :p:

and Quackster nice release, I don't think I have the knowledge to do anything with this but the more complete the better of course!
 
Developer
Developer
Joined
Dec 11, 2010
Messages
2,955
Reaction score
2,688
Well.. i'm a oldskooler, so i guess i will response to this. Alex u did a great job again. handfull for guys who loves the old retro's. I miss those days :)

And happy new year buddy, and for everyone who knows me.

Smell ya later.

Hey thank you, speaking of which, did you ever do any encryption stuff for v30+?
 
Newbie Spellweaver
Joined
Nov 10, 2020
Messages
6
Reaction score
3
Well.. i'm a oldskooler, so i guess i will response to this. Alex u did a great job again. handfull for guys who loves the old retro's. I miss those days :)

And happy new year buddy, and for everyone who knows me.

Smell ya later.
Now there's a name I certainly remember.. welcome back. Quite suprising how many users are still interested in old school, shockwave development.

Anyway, excellent work as always Quackster this poop makes me feel hella old.
 

AWA

Master Summoner
Loyal Member
Joined
Feb 24, 2008
Messages
595
Reaction score
389
I remember people saying that decompiling the old Shockwave clients would be impossible – it's cool to see that they were proven wrong! There were several features I wanted to implement back in the day, but I could only do so much with missing packet logs.

Anyways, nice to see you're still making cool stuff Quackster, and happy new year!
 
The World Is Yours
Loyal Member
Joined
Jun 19, 2007
Messages
1,668
Reaction score
147
It's mind blowing to still see this old school stuff in 2021/22 and I'm glad you are keeping the retro development alive. Well done.

Do people still play old school retros anymore? Let alone the official Habbo Hotel?
 
Newbie Spellweaver
Joined
May 17, 2008
Messages
9
Reaction score
5
Do people still play old school retros anymore? Let alone the official Habbo Hotel?

Sure. That's the nostalgia. The modern hotel or any fancy modded hotel don't have that for me. If I need a kick of nostalgia then I start the client on the SDD and sit in a kind of time capsule. That's why I'm still interested in the first place. And thanks to Quackster and everyone who contributes, the experience is so good that i can really immerse myself. They keep something great alive
 
Developer
Developer
Joined
Dec 11, 2010
Messages
2,955
Reaction score
2,688
I remember people saying that decompiling the old Shockwave clients would be impossible – it's cool to see that they were proven wrong! There were several features I wanted to implement back in the day, but I could only do so much with missing packet logs.

Anyways, nice to see you're still making cool stuff Quackster, and happy new year!

Yeah understandable, being able to decompile Shockwave is a relatively recent development, probably only a few years old now :>

The trick is to decompress the .cct and .dcr and then have the ability to read the bytecode.
 
Joined
Feb 26, 2007
Messages
570
Reaction score
617
Well.. i'm a oldskooler, so i guess i will response to this. Alex u did a great job again. handfull for guys who loves the old retro's. I miss those days :)

And happy new year buddy, and for everyone who knows me.

Smell ya later.

Another oldie checking in! I'm no longer around the scene these days, however this brings back some fond memories! Nice to see the release, hope you're well!
 
ThuGie.NL - Webmaster
Joined
Apr 16, 2006
Messages
607
Reaction score
55
I also remember my first habbo server, it was such a headache figuring out parts of the protocol as it just didnt exist in any of the already pre-existing servers..
No decompiler as well pff.
 
Custom Title Activated
Loyal Member
Joined
Oct 26, 2012
Messages
2,357
Reaction score
1,086
I wish more encryptions for later versions (v22+ or something), especially for the v31+ era, sadly it's too complicated for me. I really appreciate your amazing contributions even though they're for older versions.
 
Developer
Developer
Joined
Dec 11, 2010
Messages
2,955
Reaction score
2,688
I wish more encryptions for later versions (v22+ or something), especially for the v31+ era, sadly it's too complicated for me. I really appreciate your amazing contributions even though they're for older versions.

You're welcome! I could look into doing encryption for most Habbo shockwave versions for v9-20~ something (sadly when it gets to v30+ they introduced the Diffie-Hellman key exchange and that is far beyond my knowledge and I'm not sure if I can do that on my own). I know Woodpecker has v14 RC4 done, however.
 
Custom Title Activated
Loyal Member
Joined
Oct 26, 2012
Messages
2,357
Reaction score
1,086
You're welcome! I could look into doing encryption for most Habbo shockwave versions for v9-20~ something (sadly when it gets to v30+ they introduced the Diffie-Hellman key exchange and that is far beyond my knowledge and I'm not sure if I can do that on my own). I know Woodpecker has v14 RC4 done, however.

V9-v20 shouldn't be too hard. After that they started using premix tables and that kinda stuff, not sure how that worked exactly lmao. And then after some versions DH which I kinda understand however I am not able to get it fully working (I get d/c when I send @A)
 
Developer
Developer
Joined
Dec 11, 2010
Messages
2,955
Reaction score
2,688
V9-v20 shouldn't be too hard. After that they started using premix tables and that kinda stuff, not sure how that worked exactly lmao. And then after some versions DH which I kinda understand however I am not able to get it fully working (I get d/c when I send @A)

Yeah because the @A public key is numbers only, client will crash if you add letters because it parses every character as an integer.
 
Back
Top