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; }
private void buttonNoEncoding_Click(object sender, EventArgs e) { var bytes = File.ReadAllBytes(textBoxRaw.Text); var(header, body) = SplitBmpHeaderFromBody(bytes); var message = MessageTools.BuildMessage(body, Constants.BitsInByte); var passed = _channel.Pass(message); var passedBodyBytes = passed.Vectors .Select(v => v.Bits.ToByte()); var fileBytes = header.Concat(passedBodyBytes).ToArray(); File.WriteAllBytes(textBoxNoEnc.Text, fileBytes); }
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); }