private void InitQuestion()
        {
            if (_countQuestion >= EncodingCountConfiguration.GetCountByTest
                    (EncoderType.Elgamal))
            {
                _encodersForm.panelQuestion.Controls.Remove(this);

                _encodersForm.panelQuestion.Controls.Add(new FinishControl(_countCorrectQuestion, _countQuestion));
            }

            IElgamalQuestion elgamalQuestion = (IElgamalQuestion)_mainPresentation
                                               .GenerateQuestion
                                                   (_codingType, EncoderType.Elgamal);

            tbA.Text = elgamalQuestion.A.ToString();
            tbP.Text = elgamalQuestion.P.ToString();
            tbB.Text = elgamalQuestion.B.ToString();
            tbR.Text = elgamalQuestion.R.ToString();

            switch (_codingType)
            {
            case CodingType.Decoding:
                tbMessage.Text = elgamalQuestion.Description;
                // tbMessage.ReadOnly = true;
                tbO.Text = String.Empty;
                tbW.Text = String.Empty;
                break;

            case CodingType.Encoding:
                string descript = elgamalQuestion.Description;
                var    values   = descript.Split(',');
                tbO.Text = values[0];
                tbW.Text = values[1];
                //   tbO.ReadOnly = true;
                //   tbW.ReadOnly = true;
                tbMessage.Text = String.Empty;
                break;
            }


            _countQuestion++;
            lbCurrentTask.Text = _countQuestion.ToString();
        }
Exemplo n.º 2
0
        public IQuestionValue GenerateQuestion(CodingType codingType, EncoderType encodingType)
        {
            IQuestionValue value = new QuestionValue();

            int           countNumber = _random.Next(6, 10);
            StringBuilder question    = new StringBuilder();
            List <int>    primes      = new List <int>();

            switch (encodingType)
            {
            case EncoderType.Caesar:
                value.Description = RandomGenerator.NextENGMessage(5);
                break;

            case EncoderType.Vigenere:
                value.Description = RandomGenerator.NextENGMessage(5);
                break;

            case EncoderType.DiffiHelman:
                value = new DiffiHelmanQuestion();
                IDiffiHelmanQuestion diffiHelman = (IDiffiHelmanQuestion)value;
                primes = GetPrimes(203);

                diffiHelman.N = primes[_random.Next(0, primes.Count)];
                diffiHelman.Q = _random.Next(2, diffiHelman.N - 1);
                diffiHelman.X = _random.Next(11, 100);
                diffiHelman.Y = _random.Next(11, 100);
                value         = diffiHelman;
                break;

            case EncoderType.RSA:
                value = new DiffiHelmanQuestion();
                IDiffiHelmanQuestion diffiHelman1 = (IDiffiHelmanQuestion)value;
                primes         = GetPrimes(40);
                diffiHelman1.N = primes[_random.Next(2, primes.Count)];
                diffiHelman1.Q = _random.Next(2, diffiHelman1.N - 1);
                diffiHelman1.X = _random.Next(11, 40);
                value          = diffiHelman1;
                break;

            case EncoderType.Elgamal:
                primes = GetPrimes(203);
                value  = new ElgamalQuestion();
                IElgamalQuestion elgmal = (IElgamalQuestion)value;
                elgmal.P = primes[_random.Next(2, primes.Count)];
                elgmal.A = _random.Next(3, elgmal.P - 1);
                elgmal.B = _random.Next(1, elgmal.P - 2);
                elgmal.R = _random.Next(1, elgmal.P - 1);

                switch (codingType)
                {
                case CodingType.Encoding:
                    elgmal.Description = $"{_random.Next(2, 20)},{_random.Next(2, 200)}";
                    break;

                case CodingType.Decoding:
                    elgmal.Description = $"{_random.Next(2, 20)}";
                    break;
                }
                break;
            }

            return(value);
        }