Пример #1
0
        private void buttonRunWithEncoding_Click(object sender, System.EventArgs e)
        {
            if (!textBoxRaw.Text.Any())
            {
                return;
            }
            var bytes              = Encoding.ASCII.GetBytes(textBoxRaw.Text);
            var originalSize       = bytes.Length * Constants.BitsInByte;
            var message            = MessageTools.BuildMessage(bytes, _generatorMatrix.EncodableVectorSize);
            var encoded            = _encoder.Encode(message);
            var passed             = _channel.Pass(encoded);
            var decoded            = _decoder.Decode(passed);
            var bitsOfOriginalSize = decoded.Vectors
                                     .SelectMany(v => v.Bits)
                                     .Take(originalSize)
                                     .ToList();//only take the original bytes, ignore anything that was added by padding)

            var decodedBytes = bitsOfOriginalSize
                               .Batch(Constants.BitsInByte)// batch by byte bit size
                               .Select(bits => bits.ToList().ToByte())
                               .ToArray();

            var resultString = Encoding.ASCII.GetString(decodedBytes);

            textBoxWithEncoding.Text = resultString;
        }
Пример #2
0
        private void buttonWithEncoding_Click(object sender, EventArgs e)
        {
            var bytes = File.ReadAllBytes(textBoxRaw.Text);

            var(header, body) = SplitBmpHeaderFromBody(bytes);

            var originalSize = body.Length * Constants.BitsInByte;
            var message      = MessageTools.BuildMessage(body, _generatorMatrix.EncodableVectorSize);
            var encoded      = _encoder.Encode(message);
            var passed       = _channel.Pass(encoded);
            var decoded      = _decoder.Decode(passed);
            var decodedBytes = decoded.Vectors
                               .SelectMany(v => v.Bits)
                               .Take(originalSize)          //only take the original bytes, ignore anything that was added by padding
                               .Batch(Constants.BitsInByte) // batch by byte bit size
                               .Select(bits => bits.ToList().ToByte());

            //add header back
            var fileBytes = header
                            .Concat(decodedBytes)
                            .ToArray();

            File.WriteAllBytes(textBoxWithEnc.Text, fileBytes);
        }