Example #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;
        }
Example #2
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;
        }