private void DiffieHellmanProcessButton_Click(object sender, EventArgs e) { if (this.DiffieHellmanGetOwnPrivateKeyLabel.Text.Length > 0) { if (this.DiffieHellmanKeyTextBox.Text.Length > 0) { string temp = Regex.Replace(this.DiffieHellmanKeyTextBox.Text, " ", string.Empty); temp = CiphersDeciphers.TransformKeyString(temp, Convert.ToInt32(this.DiffieHellmanGetOwnPrivateKeyLabel.Text)); this.DiffieHellmanAfterProcessTextBox.Text = CiphersDeciphers.VigenereEncodeDecode( this.DiffieHellmanBeforeProcessTextBox.Text, temp, this.DiffieHellmanIsToCipher ); } else { MessageBox.Show( "Введите ключ", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Error ); } } }
private void DiffieHellmanGetPartnerPrivateKeyButton_Click(object sender, EventArgs e) { if (this.DiffieHellmanPartnerKeyUpDown.Value > 0 && this.DiffieHellmanOwnKeyResultLabel.Text != String.Empty) { string[] result = this.DiffieHellmanResultLabel.Text.Split(','); var prime = BigInteger.Parse(result[0]); var gen = BigInteger.Parse(this.DiffieHellmanOwnKeyResultLabel.Text); var key = Convert.ToInt16(this.DiffieHellmanPartnerKeyUpDown.Value); this.DiffieHellmanGetPartnerPrivateKeyLabel.Text = CiphersDeciphers.DiffieHellmanCalcKey(key, gen, prime).ToString(); } }
private void DiffieHellmanCalcPartnerKeyButton_Click(object sender, EventArgs e) { if (this.DiffieHellmanResultLabel.Text.Length > 0) { string[] result = this.DiffieHellmanResultLabel.Text.Split(','); var prime = BigInteger.Parse(result[0]); var gen = BigInteger.Parse(result[1]); var key = Convert.ToInt16(this.DiffieHellmanPartnerKeyUpDown.Value); System.Console.WriteLine($"{gen}, {prime}, {key}"); this.DiffieHellmanPartnerKeyResultUpDown.Value = Convert.ToDecimal(CiphersDeciphers.DiffieHellmanCalcKey(key, gen, prime).ToString()); } }
private void DiffieHellmanCalcOwnKeyButton_Click(object sender, EventArgs e) { if (this.DiffieHellmanResultLabel.Text.Length > 0) { string[] result = this.DiffieHellmanResultLabel.Text.Split(','); int prime = Convert.ToInt32(result[0]); int gen = Convert.ToInt32(result[1]); var key = Convert.ToInt16(this.DiffieHellmanOwnKeyUpDown.Value); System.Console.WriteLine($"{gen}, {prime}, {key}"); this.DiffieHellmanOwnKeyResultLabel.Text = CiphersDeciphers.DiffieHellmanCalcKey(key, gen, prime).ToString(); } }
private void CaesarProcessButton_Click(object sender, EventArgs e) { if (this.CaesarBeforeProcessTextBox.Text != null) { this.CaesarAfterProcessTextBox.Text = (this.CaesarIsToCipher) ? this.CaesarAfterProcessTextBox.Text = CiphersDeciphers.CaesarEncodeDecode( Convert.ToInt32(this.CaesarStepUpDown.Value), this.CaesarBeforeProcessTextBox.Text ) : this.CaesarAfterProcessTextBox.Text = CiphersDeciphers.CaesarEncodeDecode( -Convert.ToInt32(this.CaesarStepUpDown.Value), this.CaesarBeforeProcessTextBox.Text ); } }
private void DiffieHellmanSendOpenKeyButton_Click(object sender, EventArgs e) { var prime = Convert.ToInt32(this.DiffieHellmanPrimeUpDown.Value); var gen = Convert.ToInt32(this.DiffieHellmanGeneratorUpDown.Value); //if input is number if (CiphersDeciphers.IsPrime(prime) && CiphersDeciphers.IsPrimitiveRoot(gen, prime)) { this.DiffieHellmanResultLabel.Text = $"{prime},{gen}"; } else { MessageBox.Show( "Ключ введён неверно", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error ); } }
private void VigenereProcessButton_Click(object sender, EventArgs e) { if (this.VigenereKeyTextBox.Text.Length > 0) { string temp = Regex.Replace(this.VigenereKeyTextBox.Text, " ", string.Empty); this.VigenereAfterProcessTextBox.Text = CiphersDeciphers.VigenereEncodeDecode( this.VigenereBeforeProcessTextBox.Text, temp, this.VigenereIsToCipher ); } else { MessageBox.Show( "Введите ключ", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Error ); } }
private void DiffieHellmanButton_Click(object sender, EventArgs e) { int number = Convert.ToInt32(this.DiffieHellmanInsertUpDown.Value); if (number > 2 && number <= 2000) { KeyValuePair <int, int>?buff = CiphersDeciphers.SetDictionaryOfPublicKeys(number); if (buff != null) { this.DiffieHellmanPrimeUpDown.Value = buff.Value.Key; this.DiffieHellmanGeneratorUpDown.Value = buff.Value.Value; } } else { MessageBox.Show( "Введите корректное число от 3 до 1000", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error ); } }