~ruther/NosSmooth

ref: 8c094d4604a7c0834cde6c821592beafb844fe0c NosSmooth/Core/NosSmooth.Cryptography/ClientLoginCryptography.cs -rw-r--r-- 1.4 KiB
8c094d46 — Rutherther feat(pcap): delete only not seen connections 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
//  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)
    {
        try
        {
            var output = new StringBuilder(bytes.Length);
            foreach (var c in bytes)
            {
                output.Append(Convert.ToChar(c - 0xF));
            }

            return output.ToString();
        }
        catch
        {
            return string.Empty;
        }
    }

    /// <inheritdoc />
    public byte[] Encrypt(string value, Encoding encoding)
    {
        try
        {
            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;
        }
        catch
        {
            return Array.Empty<byte>();
        }
    }
}