private void decrypt_Click(object sender, RoutedEventArgs e) { int count = 0; string text_a = textA.Text; text_a.Trim(); string text_b = textB.Text; text_b.Trim(); for (int i = 0; i < text_a.Length; i++) { if (text_a[i] == 32) { count++; } } count++; int[] a = CheckInput(text_a, count); int[] b = CheckInput(text_b, count); int p = Convert.ToInt32(keyP.Text); int x = Convert.ToInt32(keyX.Text); Gamal elGamal = new Gamal(); string result = ""; for (int i = 0; i < count; i++) { result += elGamal.Decrypt(p, x, a[i], b[i]); } cipher.Text = result; }
private void encrypt_Click(object sender, RoutedEventArgs e) { KeyGen key = new KeyGen(); int p = key.GenerateP(); int g = key.GenerateG(p); int x = key.GenerateX(p); int y = key.FastExponentiation(p, g, x); cipher_a.Text = ""; cipher_b.Text = ""; string src = source.Text; Gamal elGamal = new Gamal(); int[] res = new int[2]; for (int i = 0; i < src.Length; i++) { int symbol = Convert.ToInt32(source.Text[i]); res = elGamal.Encrypt(p, g, y, symbol); cipher_a.Text += Convert.ToString(res[0]); cipher_b.Text += Convert.ToString(res[1]); cipher_a.Text += " "; cipher_b.Text += " "; } keyP.Text = Convert.ToString(p); keyG.Text = Convert.ToString(g); keyY.Text = Convert.ToString(y); keyX.Text = Convert.ToString(x); }