~ruther/NosSmooth

ref: 6f3e76849e73a8b0f1642a96b2eb6cab42e68ac1 NosSmooth/Core/NosSmooth.Cryptography/ClientLoginCryptography.cs -rw-r--r-- 1.1 KiB
6f3e7684 — Rutherther fix(crypto): remove client world cryptography encoding conversion that does not work correctly 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
//  ClientLoginCryptography.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Text;

namespace NosSmooth.Cryptography;

/// <summary>
/// A cryptography used for logging to NosTale server from the client.
/// </summary>
public class ClientLoginCryptography : ICryptography
{
    private static readonly Random Random = new Random(DateTime.Now.Millisecond);

    /// <inheritdoc />
    public string Decrypt(in ReadOnlySpan<byte> bytes, Encoding encoding)
    {
        var output = new StringBuilder();
        foreach (var c in bytes)
        {
            output.Append(Convert.ToChar(c - 0xF));
        }

        return output.ToString();
    }

    /// <inheritdoc />
    public byte[] Encrypt(string value, Encoding encoding)
    {
        var output = new byte[value.Length + 1];
        for (int i = 0; i < value.Length; i++)
        {
            output[i] = (byte)((value[i] ^ 0xC3) + 0xF);
        }
        output[output.Length - 1] = 0xD8;
        return output;
    }
}