public DiscreteLogAlgorithmsInfoForm() { InitializeComponent(); textBox1.Select(0, 0); // textBox2.Select(0, 0); base1 = new BigInteger(r.Next(100000) + 2); base2 = new BigInteger(r.Next(100000) + 2); mod1 = CryptoMath.genSimpleRand(8); if (mod1 == base1) { mod1++; } mod2 = CryptoMath.genSimpleRand(8); if (mod2 == base2) { mod1++; } BigInteger rnd1 = CryptoMath.genRand(100000); BigInteger rnd2 = CryptoMath.genRand(100000); num1 = BigInteger.ModPow(base1, rnd1, mod1); num2 = BigInteger.ModPow(base2, rnd2, mod2); Task1Label.Text = base1.ToString() + "^x = " + num1.ToString() + " mod " + mod1.ToString(); Task2Label.Text = base2.ToString() + "^x = " + num2.ToString() + " mod " + mod2.ToString(); }
private void testBtn_Click(object sender, EventArgs e) { this.Enabled = false; ansLabel.Visible = false; BigInteger testInt; BigInteger.TryParse(inputBox.Text, out testInt); if (testInt > 0) { if (CryptoMath.isPrime(testInt)) { ansLabel.Text = "Введённое число - простое"; } else { ansLabel.Text = "Введённое число - составное"; } } else { ansLabel.Text = "Введено неправильное значение"; } ansLabel.Visible = true; this.Enabled = true; }
private void genpgBtn_Click(object sender, EventArgs e) { string pstr; switch (digitsBox.Text) { case "p40": pstr = "7524548124131735373612526345481757634861"; BigInteger.TryParse(pstr, out p); g = 7; break; case "p41": pstr = "61571157514825784611687343327637886854113"; BigInteger.TryParse(pstr, out p); g = 3; break; default: p = CryptoMath.genSimpleRand(digits); g = CryptoMath.calculateFakePrimitiveRoot(p); break; } pBox.Text = p.ToString(); gBox.Text = g.ToString(); }
//генерация р private void generatepBtn_Click(object sender, EventArgs e) { p = CryptoMath.genSimpleRand(digits); gtextBox.Text = ""; xtextBox.Text = ""; ytextBox.Text = ""; ptextBox.Text = p.ToString(); }
private void generatekBtn_Click(object sender, EventArgs e) { do { k = CryptoMath.genRand(20); } while (k > p - 1); kBox.Text = k.ToString(); }
private void fakeGenBtn_Click(object sender, EventArgs e) { if (modulo < 3) { pBox.Text = "12345"; } primit = CryptoMath.calculateFakePrimitiveRoot(modulo); fakeBox.Text = primit.ToString(); }
private void genkBtn_Click(object sender, EventArgs e) { // matan.DIGITS = 10; do { k = CryptoMath.genRand(10); } while (k > p - 1); kBox.Text = k.ToString(); }
private void calcBtn_Click(object sender, EventArgs e) { this.Enabled = false; input = BigInteger.Parse(inputBox.Text); input = CryptoMath.phi(input); outputBox.Text = input.ToString(); label2.Visible = true; outputBox.Visible = true; this.Enabled = true; }
private void generatexBtn_Click(object sender, EventArgs e) { if (p > 2) { do { x = CryptoMath.genRand(digits); }while (x == 0 || x >= p); } xtextBox.Text = x.ToString(); }
private void button1_Click(object sender, EventArgs e) { if (BigInteger.TryParse(answerBox1.Text, out ans1) && BigInteger.TryParse(answerBox2.Text, out ans2) && BigInteger.TryParse(answerBox3.Text, out ans3)) { Answers.EulerAnswers[0] = (ans1 == CryptoMath.phi(fi1)); Answers.EulerAnswers[1] = (ans2 == CryptoMath.phi(fi2)); Answers.EulerAnswers[2] = (ans3 == CryptoMath.phi(fi3)); //var newForm = new TutorForm3(); //newForm.Show(); Answers.interruptTutorial = false; this.Close(); } }
private void RandomDataButton_Click(object sender, EventArgs e) { Random rand = new Random(); int size = rand.Next(11) + 2; BigInteger M = 0; while (!CryptoMath.isPrime((M - 1) / 2)) { M = CryptoMath.genSimpleRand(size); } MBox.Text = M.ToString(); ABox.Text = (CryptoMath.genRand(rand.Next(size - 1) + 1) + 2).ToString(); BBox.Text = (CryptoMath.genRand(rand.Next(size - 1) + 1)).ToString(); }
private void generategBtn_Click(object sender, EventArgs e) { this.Enabled = false; if (p > 2) { if (CryptoMath.DIGITS > 10) { g = CryptoMath.calculateFakePrimitiveRoot(p); } else { g = CryptoMath.calculatePrimitiveRoot(p); } } gtextBox.Text = g.ToString(); this.Enabled = true; }
private void nextBtn_Click(object sender, EventArgs e) { if (CryptoMath.isPrime(p) && p > 2 && x > 1 && g > 1 && y > 0) { //var newForm = new TutorForm6(g, p, y, x); //newForm.Show(); Answers.g = g; Answers.p = p; Answers.y = y; Answers.x = x; Answers.interruptTutorial = false; this.Close(); } if (!CryptoMath.isPrime(p)) { wrongpLabel.Visible = true; } }
private void generatepBtn_Click(object sender, EventArgs e) { modulo = CryptoMath.genSimpleRand(digits); pBox.Text = modulo.ToString(); }
private void PohligButton_Click(object sender, EventArgs e) { BSGSProgressBar.Value = 0; BigInteger a, b, m, answer; a = 0; b = 0; m = 0; answer = 0; ResultLabel.Visible = false; ResultLabel.ForeColor = Color.Red; BigInteger.TryParse(ABox.Text, out a); BigInteger.TryParse(BBox.Text, out b); BigInteger.TryParse(MBox.Text, out m); if (a < 2 || b < 0 || m < 3 || b > m) { ResultLabel.Text = "Неправильный ввод данных"; } else if (!(CryptoMath.isPrime(m))) { ResultLabel.Text = "М должно быть простым"; } else { if (m.ToString().Length > 5) { ResultLabel.Text = "Слишком большое М - \nВозможно крайне долгое время работы"; ResultLabel.Visible = true; } try { BSGSProgressBar.Visible = true; this.Enabled = false; answer = SilverPohligHellman.PohligHellman(a, b, m, BSGSProgressBar); } catch (OutOfMemoryException) { ResultLabel.Text = "Нехватка оперативной памяти"; ResultLabel.Visible = true; this.Enabled = true; return; } if (answer == -1) { ResultLabel.Text = "Такого Х не найдено"; } else { ResultLabel.ForeColor = Color.Green; ResultLabel.Text = $"X = {answer}"; if (BigInteger.ModPow(a, answer, m) != b) { ResultLabel.ForeColor = Color.Red; ResultLabel.Text = "Такого Х не найдено"; } // ResultLabel.Text += "?"; } } BSGSProgressBar.Visible = false; ResultLabel.Visible = true; this.Enabled = true; }