Esempio n. 1
0
        private void hideMessage_Click(object sender, EventArgs e)
        {
            ulong[] CodedText = Coding.Encoding(Message);
            ulong   hash      = Hash.GetHash(CodedText, OpenKey, Module);

            ulong[]      RandomStorage;
            List <ulong> Random            = new List <ulong>();
            string       StringRandomRange = "1";
            int          EilerLength       = Module.ToString().Length;

            for (int i = 0; i < EilerLength / 2; ++i)
            {
                StringRandomRange += "0";
            }
            ulong RandomRange = Module - Convert.ToUInt64(StringRandomRange);

            for (ulong i = RandomRange; i < Module; ++i)
            {
                if (1 == Euclid.FindGSD(i, Module))
                {
                    Random.Add(i);
                }
            }
            RandomStorage = Random.ToArray();
            Random rand = new Random();
            ulong  k    = RandomStorage[rand.Next(0, RandomStorage.Length)];

            reverseK     = ExtendedEuclid.FindReverse(k, Module);
            HidedMessage = (hash * ExpByModule.Exponentiation(k, OpenKey, Module)) % Module;
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.textBox7.Text = "";
            ulong[] CodedText = Coding.Encoding(Message);
            ulong   hash      = Hash.GetHash(CodedText, OpenKey, P) % Q;

            if (0 == hash)
            {
                hash = 1;
            }
            Random rand = new Random();
            ulong  K    = (ulong)rand.Next(0, (int)Q);

            ulong[] sign = new ulong[2];
            sign[0] = ExpByModule.Exponentiation(A, K, P) % Q;
            sign[1] = (SecretKey * sign[0] + K * hash) % Q;
            if (0 == sign[0])
            {
                bool check = true;
                while (check)
                {
                    K       = (ulong)rand.Next(0, (int)Q);
                    sign[0] = ExpByModule.Exponentiation(A, K, P) % Q;
                    sign[1] = (SecretKey * sign[0] + K * hash) % Q;
                    if (0 != sign[0])
                    {
                        check = false;
                    }
                }
            }
            Signature = sign;
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            ulong[] CodedText = Coding.Encoding(Message);
            ulong   hash      = Hash.GetHash(CodedText, OpenKey, P) % Q;

            if (0 == hash)
            {
                hash = 1;
            }
            ulong v  = ExpByModule.Exponentiation(hash, Q - 2, Q);
            ulong z1 = (Signature[1] * (v % Q)) % Q;
            ulong z2 = (((Q - Signature[0]) % Q) * v) % Q;
            ulong u  = ((ExpByModule.Exponentiation(A, z1, P) * ExpByModule.Exponentiation(OpenKey, z2, P)) % P) % Q;

            this.textBox7.Text = u.ToString();
            this.textBox8.Text = Signature[0].ToString();
            if (u == Signature[0])
            {
                this.label9.Text = "Цифровая подпись действительна";
            }
            else
            {
                this.label9.Text = "Цифровая подпись не действительна";
            }
        }
Esempio n. 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            ulong[] CodedText = Coding.Encoding(this.textBox5.Text);
            ulong   hash      = Hash.GetHash(CodedText, Convert.ToUInt64(this.textBox3.Text), Convert.ToUInt64(this.textBox1.Text) * Convert.ToUInt64(this.textBox2.Text));

            this.textBox6.Text = ExpByModule.Exponentiation(hash, Convert.ToUInt64(this.textBox4.Text), Convert.ToUInt64(this.textBox1.Text) * Convert.ToUInt64(this.textBox2.Text)).ToString();
        }
Esempio n. 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            ulong[] CodedText = Coding.Encoding(Message);
            ulong   hash      = Hash.GetHash(CodedText, OpenKey, P);

            FirstVerification  = ExpByModule.Exponentiation(G, hash, P).ToString();
            SecondVerification = ((ExpByModule.Exponentiation(OpenKey, Signature[0], P) * ExpByModule.Exponentiation(Signature[0], Signature[1], P)) % P).ToString();
            if (FirstVerification == SecondVerification)
            {
                this.label9.Text = "Цифровая подпись действительна";
            }
            else
            {
                this.label9.Text = "Цифровая подпись не действительна";
            }
        }
Esempio n. 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.label5.Visible   = true;
            this.textBox4.Visible = true;
            this.button2.Visible  = true;
            ulong openkey = Convert.ToUInt64(this.textBox1.Text);
            ulong module  = Convert.ToUInt64(this.textBox2.Text);
            RSA   rsa     = new RSA(openkey, "Открытый");

            ulong[] code         = Coding.Encoding(this.textBox3.Text);
            ulong[] cypher       = rsa.Encription(code, module);
            int     CypherLength = cypher.Length;

            for (int i = 0; i < CypherLength; ++i)
            {
                this.textBox4.Text += cypher[i].ToString();
            }
            frm1.Cypher = cypher;
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
 private void button1_Click(object sender, EventArgs e)
 {
     ulong[] CodedText = Coding.Encoding(this.textBox3.Text);
     this.textBox5.Text = Hash.GetHash(CodedText, Convert.ToUInt64(this.textBox1.Text), Convert.ToUInt64(this.textBox2.Text)).ToString();
 }