Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Nostale
You last visited: Today at 19:20

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Nostale World Encryption

Discussion on Nostale World Encryption within the Nostale forum part of the MMORPGs category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2010
Posts: 133
Received Thanks: 29
Nostale World Encryption

Hi
ich versuche das:
Code:
public static string Decrypt2(string str)
        {
            List<byte> receiveData = new List<byte>();
            char[] table = { ' ', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'n' };
            int count;
            for (count = 0; count < str.Length; count++)
            {
                if (str[count] <= 0x7A)
                {
                    int len = str[count];

                    for (int i = 0; i < len; i++)
                    {
                        count++;

                        try
                        {
                            receiveData.Add(unchecked((byte)(str[count] ^ 0xFF)));
                        }
                        catch
                        {
                            receiveData.Add(255);
                        }
                    }
                }
                else
                {
                    int len = str[count];
                    len &= 0x7F;

                    for (int i = 0; i < len; i++)
                    {
                        count++;
                        int highbyte;
                        try
                        {
                            highbyte = str[count];
                        }
                        catch
                        {
                            highbyte = 0;
                        }
                        highbyte &= 0xF0;
                        highbyte >>= 0x4;

                        int lowbyte;
                        try
                        {
                            lowbyte = str[count];
                        }
                        catch
                        {
                            lowbyte = 0;
                        }
                        lowbyte &= 0x0F;

                        if (highbyte != 0x0 && highbyte != 0xF)
                        {
                            receiveData.Add(unchecked((byte)table[highbyte - 1]));
                            i++;
                        }

                        if (lowbyte != 0x0 && lowbyte != 0xF)
                        {
                            receiveData.Add(unchecked((byte)table[lowbyte - 1]));
                        }
                    }
                }
            }
            return Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, receiveData.ToArray()));
}

public override string Decrypt(byte[] str, int sessionId = 0)
        {
            string encrypted_string = "";
            int session_key = sessionId & 0xFF;
            byte session_number = unchecked((byte)(sessionId >> 6));
            session_number &= 0xFF;
            session_number &= unchecked((byte)0x80000003);

            switch (session_number)
            {
                case 0:
                    foreach (byte character in str)
                    {
                        byte firstbyte = unchecked((byte)(session_key + 0x40));
                        byte highbyte = unchecked((byte)(character - firstbyte));
                        encrypted_string += (char)highbyte;
                    }
                    break;

                case 1:
                    foreach (byte character in str)
                    {
                        byte firstbyte = unchecked((byte)(session_key + 0x40));
                        byte highbyte = unchecked((byte)(character + firstbyte));
                        encrypted_string += (char)highbyte;
                    }
                    break;

                case 2:
                    foreach (byte character in str)
                    {
                        byte firstbyte = unchecked((byte)(session_key + 0x40));
                        byte highbyte = unchecked((byte)(character - firstbyte ^ 0xC3));
                        encrypted_string += (char)highbyte;
                    }
                    break;

                case 3:
                    foreach (byte character in str)
                    {
                        byte firstbyte = unchecked((byte)(session_key + 0x40));
                        byte highbyte = unchecked((byte)(character + firstbyte ^ 0xC3));
                        encrypted_string += (char)highbyte;
                    }
                    break;

                default:
                    encrypted_string += (char)0xF;
                    break;
            }

            string[] temp = encrypted_string.Split((char)0xFF);
            string save = "";

            for (int i = 0; i < temp.Length; i++)
            {
                save += Decrypt2(temp[i]);
                if (i < temp.Length - 2)
                {
                    save += (char)0xFF;
                }
            }

            return save;
}
in Python3 zu übersetzen, die ersten Zahlen werden richtig dargestellt der rest jedoch nicht.

Das ist meine Function:
Code:
def decrypt2(_packet):
    decrypted_string = ''
    table = [' ', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'n']

    count = 0
    while count < len(_packet):
        if ord(_packet[count]) <= 0x7A:
            _len = ord(_packet[count])
            for i in range(1, _len):
                count += 1
                decrypted_string += chr(ord(_packet[count]) ^ 0xFF)
        else:
            _len = ord(_packet[count])
            _len &= 0x7F

            i = 0
            while i < _len:
                count += 1

                try:
                    highbyte = ord(_packet[count])
                    highbyte &= 0xF0
                    highbyte >>= 0x4
                except IndexError:
                    highbyte = 0

                try:
                    lowbyte = ord(_packet[count])
                    lowbyte &= 0x0F
                except IndexError:
                    lowbyte = 0

                if highbyte != 0x0 and highbyte != 0xF:
                    decrypted_string += table[highbyte - 1]

                if lowbyte != 0x0 and lowbyte != 0xF:
                    decrypted_string += table[lowbyte - 1]

                i += 1
            count += 1
    print('Decrypted:', decrypted_string)
    return decrypted_string

def decrypt(_packet, session_id):
    encrypted_string = ""
    session_key = session_id & 0xFF
    session_number = session_id >> 6
    session_number &= 0xFF
    session_number &= 0x80000003


    if session_number == 0:
        for i in range(0, len(_packet)):
            firstbyte = session_key + 0x40
            highbyte = (int(_packet[i]) - firstbyte)
            encrypted_string += chr(highbyte)
    elif session_number == 1:
        for i in range(0, len(_packet)):
            firstbyte = session_key + 0x40
            highbyte = (int(_packet[i]) + firstbyte)
            encrypted_string += chr(highbyte)
    elif session_number == 2:
        for i in range(0, len(_packet)):
            firstbyte = session_key + 0x40
            highbyte = (int(_packet[i]) - firstbyte) ^ 0xC3
            encrypted_string += chr(highbyte)
    elif session_number == 3:
        for i in range(0, len(_packet)):
            firstbyte = session_key + 0x40
            highbyte = (int(_packet[i]) + firstbyte) ^ 0xC3
            encrypted_string += chr(highbyte)
    else:
        encrypted_string += chr(0xF)

    temp = encrypted_string.split(chr(0xFF))
    save = ""

    for i in range(0, len(temp)):
        save += decrypt2(temp[i])
        if i < len(temp[i]) -2:
            save += chr(0xFF)

    return save
Kennt sich jemand damit aus und sieht was ich falsch mache?
PainToTheWorld is offline  
Old 07/08/2018, 12:08   #2
 
elite*gold: 0
Join Date: Jun 2018
Posts: 61
Received Thanks: 4
@ Was möchtest du damit bezwecken?
was waren denn deine Hintergründe warum du diesen Code geschrieben hast?
und was soll das jetzt genau sein?
Diese fragen stelle ich damit ich dir besser Helfen kann.
Voria is offline  
Old 07/08/2018, 12:54   #3
 
Pumba98's Avatar
 
elite*gold: 55
Join Date: Jan 2011
Posts: 1,240
Received Thanks: 1,187
Quote:
Originally Posted by Voria View Post
@ Was möchtest du damit bezwecken?
was waren denn deine Hintergründe warum du diesen Code geschrieben hast?
und was soll das jetzt genau sein?
Diese fragen stelle ich damit ich dir besser Helfen kann.
Er will den Code von c# nach Python übersetzen?!
Ist die OpenNos World Encryption, aber wüsste nicht wie das beim lösen des Problems hilft.



Ich kann zwar kein/kaum Python & C#, aber wie kommst du von
for (int i = 0; i < len; i++)
auf
for i in range(1, _len)

ansonsten ist die Frage ob du sowas wie
unchecked((byte)IRGENDWAS)
korrekt umgesetzt hast, kann ich nicht wirklich was zu sagen.


Ich würde einfach mal beides parallel mit der selben Eingabe debuggen und schauen wo Unterschiede auftreten

Ansonsten kann man dir im vielleicht auch kompetenter helfen
Pumba98 is offline  
Thanks
1 User
Old 07/09/2018, 09:32   #4
 
elite*gold: 0
Join Date: Apr 2017
Posts: 3
Received Thanks: 0
@ Do you have the (encrypt function) for the world in python ?
Ethnical is offline  
Reply


Similar Threads Similar Threads
Packet Encryption Guide
03/31/2012 - EO Guides & Templates - 31 Replies
There needs to be more interest in bot making for EO, so I may aswell describe how to decrypt the packets, doesn't look like anyone else has. I look forward to seeing some bots in the making. Ask any questions if you need to. The packet encryption method is almost the same as Conquer, except new encryption keys and a slightly altered method. You can find the CO encryption guide here, or in german The first noticeble difference is the encryption keys. The new ones are uint8_t...
*HOT* Packet Encryption - Decrypt/ReEncrypt HowTo
06/07/2008 - CO2 Guides & Templates - 112 Replies
Click for quickjump for english translation: http://www.elitepvpers.com/forum/index.php?...t=15 &#entry12035 all lvl2 epvp Members quitted playing Conquer Online, so we release our Packet Encryption Guide, I hope it is usefull for all AGH's out there Urheberrechte und Copyright dieser Guide liegen bei elitepvpers.com You will not use any information obtained from this guide for malicious purposes. All information from this guide is for intellectual purposes only, and you are...
Packet encryption
09/19/2005 - Lineage 2 - 1 Replies
Hi,I'm trying to make a simple L2 bot, but i got stuck in begginning - in the packet encryption. I rewrote the l2j login thread sources (those about encryption) but it doesn't work. Has anyone any description of L2 packet encryption. And second question - what Init packet (server packet,nr. 0) means? I guess that it something related with encryption, but in l2j sources that packet content is hardcoded. Thanks for replies (if any ;) )



All times are GMT +1. The time now is 19:21.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.