示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.textBox6.Text = "";
            ulong   G   = Convert.ToUInt64(this.textBox3.Text);
            ulong   P   = Convert.ToUInt64(this.textBox2.Text);
            ulong   Y   = Convert.ToUInt64(this.textBox1.Text);
            ElGamal ElG = new ElGamal(G, P, Y, true);

            ElG.k = ElG.GetK();
            ElG.a = ElG.GetFirstCypherPart();
            ulong[] code       = Coding.Encoding(this.textBox4.Text);
            ulong[] cypher     = ElG.Encription(code);
            ulong[] fullCypher = new ulong[cypher.Length + 1];
            fullCypher[0] = ElG.a;
            int fullCypherLength = fullCypher.Length;

            for (int i = 1; i < fullCypherLength; ++i)
            {
                fullCypher[i] = cypher[i - 1];
            }
            this.textBox5.Text = ElG.a.ToString();
            for (int i = 0; i < fullCypherLength; ++i)
            {
                this.textBox6.Text += fullCypher[i].ToString();
            }
            frm3.Cypher = fullCypher;
        }
示例#2
0
        private void button3_Click(object sender, EventArgs e)
        {
            ulong P             = Convert.ToUInt64(this.textBox1.Text);
            ulong G             = Convert.ToUInt64(this.textBox2.Text);
            ulong X             = Convert.ToUInt64(this.textBox3.Text);
            bool  Is_p_prime    = IsPrime.Check(P);
            bool  Is_g_lesser_p = G < P;
            bool  Is_x_lesser_p = X < P;

            if (!Is_p_prime || !Is_g_lesser_p || !Is_x_lesser_p)
            {
                if (!Is_p_prime)
                {
                    MessageBox.Show("Число P не простое", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (!Is_g_lesser_p)
                {
                    MessageBox.Show("Число G больше P", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (!Is_x_lesser_p)
                {
                    MessageBox.Show("Число X больше P", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                ElGamal ElG = new ElGamal(P, G, X);
                this.textBox4.Text = G.ToString();
                this.textBox5.Text = P.ToString();
                this.textBox6.Text = ElG.GetOpenKey().ToString();
            }
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool Is_p_prime    = IsPrime.Check(P);
            bool Is_g_lesser_p = G < P;
            bool Is_x_lesser_p = X < P;

            if (!Is_p_prime || !Is_g_lesser_p || !Is_x_lesser_p)
            {
                if (!Is_p_prime)
                {
                    MessageBox.Show("Число P не простое", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (!Is_g_lesser_p)
                {
                    MessageBox.Show("Число G больше P", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (!Is_x_lesser_p)
                {
                    MessageBox.Show("Число X больше P", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                ElGamal elG = new ElGamal(P, G, X);
                OpenKey = elG.GetOpenKey();
            }
        }
示例#4
0
        private void button2_Click(object sender, EventArgs e)
        {
            ulong   P   = Convert.ToUInt64(this.textBox1.Text);
            ulong   G   = Convert.ToUInt64(this.textBox2.Text);
            ulong   X   = Convert.ToUInt64(this.textBox3.Text);
            ElGamal ElG = new ElGamal(P, G, X);

            ElG.a = Cypher[0];
            int CypherLength = Cypher.Length - 1;

            ulong[] cypher = new ulong[CypherLength];
            for (int i = 0; i < CypherLength; ++i)
            {
                cypher[i] = Cypher[i + 1];
            }
            ulong[] decypher = ElG.Decryption(cypher);
            this.textBox8.Text = Coding.Decoding(decypher);
        }
示例#5
0
        private void button2_Click(object sender, EventArgs e)
        {
            ElGamal elG = new ElGamal(P, G, X);
            ulong   K   = elG.GetK();

            ulong[] CodedText = Coding.Encoding(Message);
            ulong   hash      = Hash.GetHash(CodedText, OpenKey, P);
            ulong   a         = ExpByModule.Exponentiation(G, K, P);
            ulong   reverseK  = ExtendedEuclid.FindReverse(K, P - 1);
            ulong   b;

            for (ulong i = 1; ; ++i)
            {
                if (hash == ((X * a + i * K) % (P - 1)))
                {
                    b = i;
                    break;
                }
            }
            ulong[] sign = new ulong[2];
            sign[0]   = a;
            sign[1]   = b;
            Signature = sign;
        }