Example #1
0
        /// <summary>
        /// Send encoded vector through the channel with provided error probability p.
        /// </summary>
        private void SendBtn_Click(object sender, EventArgs e)
        {
            var p = panel.P;

            ReceivedVector = Channel.SendBinaryMessage(EncodedVector, p, out List <int> distortedPlaces);

            receivedVectorField.Text   = ConversionUtils.ConvertIntegerArrayToString(ReceivedVector.Data);
            distortionPlaceholder.Text = string.Join(",", distortedPlaces);
            ChangeDecodingFieldVisibility(true);
            ChangeDecodedFieldVisibility(false);
        }
Example #2
0
        /// <summary>
        /// Decode the vector which was received through the channel or altered by the user.
        /// Handle cases where after user modifications vector length is incorrect or it contains other digits than 0s or 1s
        /// </summary>
        private void DecodeBtn_Click(object sender, EventArgs e)
        {
            var vector = receivedVectorField.Text;

            if (vector.Length != ReceivedVector.Length)
            {
                MessageBox.Show($"Vector length must be {ReceivedVector.Length}!");
                return;
            }
            if (!new Regex($"^[01]+$").IsMatch(vector))
            {
                MessageBox.Show($"Vector can contain only 0 or 1.");
                return;
            }
            ReceivedVector.Data = ConversionUtils.ConvertStringToIntegerArray(vector);
            var decodedVector = ReceivedVector.Decode(M);

            decodedField.Text = ConversionUtils.ConvertIntegerArrayToString(decodedVector.Data);
            ChangeDecodedFieldVisibility(true);
        }
Example #3
0
        /// <summary>
        /// Convert input text to vector and encode it. Handle cases of incorrect format input.
        /// </summary>
        private void EncodeBtn_Click(object sender, EventArgs e)
        {
            var input = inputField.Text;

            if (input.Length != VectorLength)
            {
                MessageBox.Show($"Vector length must be {VectorLength}!");
                return;
            }
            if (!new Regex($"^[01]+$").IsMatch(input))
            {
                MessageBox.Show($"Vector can contain only 0 or 1.");
                return;
            }
            var inputVector = new Vector(input);

            EncodedVector           = inputVector.Encode(M);
            encodedVectorLabel.Text = ConversionUtils.ConvertIntegerArrayToString(EncodedVector.Data);
            ChangeEncodingFieldVisibility(true);
            ChangeDecodedFieldVisibility(false);
            ChangeDecodingFieldVisibility(false);
        }