Пример #1
0
        private void VectorEnter_OnClick(object sender, EventArgs e)
        {
            var maxLength = int.Parse(vectorLength.Text);

            if (maxLength != enterVectorTextBox.Text.Length)
            {
                MessageBox.Show($"Vector's length must be {maxLength} digits.");
                return;
            }

            _m = int.Parse(parameterMTextBox.Text);
            _r = int.Parse(parameterRTextBox.Text);

            _matrixGenerator = new MatrixGenerator(_m, _r);
            _encoder         = new Encoder(_m, _r);

            var matrix = _matrixGenerator.GenerateMatrix();

            var vectorString = enterVectorTextBox.Text;

            var vector = vectorString.ToCharArray().Select(x => int.Parse(x.ToString())).ToList();

            _encodedVector = _encoder.EncodeVector(vector, matrix);

            encodedVectorTextBox.Text = _encodedVector.ListToString();

            encodedVectorLabel.Visible   = true;
            encodedVectorTextBox.Visible = true;
            sendVectorButton.Visible     = true;
            probabilityLabel.Visible     = true;
            probabilityTextBox.Visible   = true;
        }
Пример #2
0
        private void encodeTextButton_Click(object sender, EventArgs e)
        {
            if ((_m == 0) || (_r == 0))
            {
                MessageBox.Show("Parameters are not submited!");
                return;
            }
            double probability;

            if (!double.TryParse(textProbabilityTextBox.Text, out probability))
            {
                MessageBox.Show("Probability must be a number.");
                return;
            }

            if (probability >= 1 || probability <= 0)
            {
                MessageBox.Show($"Probability must be between 0 and 1");
                return;
            }

            var text = enterTextTextBox.Text;

            var vectors = SplitIntoVectors(Encoding.UTF8, text);

            _matrixGenerator = new MatrixGenerator(_m, _r);
            var matrix = _matrixGenerator.GenerateMatrix();

            _encoder = new Encoder(_m, _r);

            //encode vectors
            var encodedVectors = vectors.Select(vector => _encoder.EncodeVector(vector, matrix)).ToList();

            var encodedVectorsString      = encodedVectors.Select(vector => vector.ListToString()).ToList();
            var plainTextVectorListString = vectors.Select(vector => vector.ListToString()).ToList();

            encodedTextTextBox.Text    = encodedVectorsString.StringListToString();
            plainTextBytesTextBox.Text = plainTextVectorListString.StringListToString();

            //send through channel
            _channel = new Channel(probability);
            var receivedEncodedVectors   = encodedVectors.Select(vector => _channel.SendVector(vector)).ToList();
            var receivedPlainTextVectors = vectors.Select(vector => _channel.SendVector(vector)).ToList();

            receivedPlainTextTextBox.Text = receivedPlainTextVectors.Select(x => x.ListToString()).ToList().StringListToString();
            receivedTextTextBox.Text      = receivedEncodedVectors.Select(x => x.ListToString()).ToList().StringListToString();


            //decode
            _decoder = new Decoder(_m, _r, matrix);
            var decodedVectors = receivedEncodedVectors.Select(vector => _decoder.Decode(vector).ListToString()).ToList();


            BytesToPlainText(receivedPlainTextVectors);
            DecodeTextVector(decodedVectors);

            ShowTextControllsAfterEncoding();
        }