~ruther/NosSmooth

ref: e0b8687280cdb96a7eefdf11c6a3df0de5f03d82 NosSmooth/Data/NosSmooth.Data.NOSFiles/Decryptors/LstDecryptor.cs -rw-r--r-- 1.0 KiB
e0b86872 — František Boháček feat(data): add .NOS file readers 3 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
//
//  LstDecryptor.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.Buffers.Binary;
using Remora.Results;

namespace NosSmooth.Data.NOSFiles.Decryptors;

/// <inheritdoc />
public class LstDecryptor : IDecryptor
{
    /// <inheritdoc />
    public Result<byte[]> Decrypt(ReadOnlySpan<byte> data)
    {
        var output = new MemoryStream();
        int linesCount = BinaryPrimitives.ReadInt32LittleEndian(data);
        data = data.Slice(4);
        for (var i = 0; i < linesCount; i++)
        {
            int lineLength = BinaryPrimitives.ReadInt32LittleEndian(data);
            data = data.Slice(4);
            ReadOnlySpan<byte> line = data.Slice(0, lineLength);
            data = data.Slice(lineLength);
            foreach (var c in line)
            {
                output.WriteByte((byte)(c ^ 0x1));
            }
            output.WriteByte((byte)'\n');
        }

        return output.ToArray();
    }
}
Do not follow this link