private void InitQuestion() { if (_countQuestion >= EncodingCountConfiguration.GetCountByTest (EncoderType.DiffiHelman)) { _encodersForm.tabPage1.Controls.Remove(this); // _encodersForm.tabPage3.Controls.Add(new FinishControl(_encodersForm)); } IDiffiHelmanQuestion diffiHelmanQuestion = (IDiffiHelmanQuestion )_mainPresentation.GenerateQuestion (CodingType.Decoding, EncoderType.DiffiHelman); tbN.Text = diffiHelmanQuestion.N.ToString(); tbG.Text = diffiHelmanQuestion.Q.ToString(); tbX.Text = diffiHelmanQuestion.X.ToString(); tbY.Text = diffiHelmanQuestion.Y.ToString(); tbKey.Text = string.Empty; _countQuestion++; lbCurrentTask.Text = _countQuestion.ToString(); }
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); }