Beispiel #1
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;
        }
Beispiel #2
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();
        }
        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;
        }
Beispiel #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 = "Цифровая подпись не действительна";
            }
        }
Beispiel #5
0
        public ulong[] Decription(ulong[] CypherText, ulong module)
        {
            int CypherTextLength = CypherText.Length;

            ulong[] OpenText = new ulong[CypherTextLength];
            for (int i = 0; i < CypherTextLength; ++i)
            {
                OpenText[i] = ExpByModule.Exponentiation(CypherText[i], Secret, module);
            }
            return(OpenText);
        }
Beispiel #6
0
        public static ulong GetHash(ulong[] Text, ulong Key, ulong Module)
        {
            int   TextLength = Text.Length;
            ulong Hash       = 0;

            for (int i = 0; i < TextLength; ++i)
            {
                Hash = (Hash ^ ExpByModule.Exponentiation(Text[i], Key, Module)) % Module;
            }
            return(Hash);
        }
Beispiel #7
0
        public ulong[] Encription(ulong[] CodedLine, ulong module)
        {
            int CodedLineLength = CodedLine.Length;

            ulong[] CypherText = new ulong[CodedLineLength];
            for (int i = 0; i < CodedLineLength; ++i)
            {
                CypherText[i] = ExpByModule.Exponentiation(CodedLine[i], Open, module);
            }
            return(CypherText);
        }
Beispiel #8
0
 private void button2_Click(object sender, EventArgs e)
 {
     this.textBox6.Text = ExpByModule.Exponentiation(Convert.ToUInt64(this.textBox4.Text), Convert.ToUInt64(this.textBox1.Text), Convert.ToUInt64(this.textBox2.Text)).ToString();
     if (this.textBox6.Text == this.textBox5.Text)
     {
         this.label8.Text = "Цифровая подпись действительна";
     }
     else
     {
         this.label8.Text = "Цифровая подпись не действительна";
     }
 }
Beispiel #9
0
        public ulong[] Encription(ulong[] CodedLine)
        {
            int CodedLineLength = CodedLine.Length;

            ulong[] CypherText = new ulong[CodedLineLength];
            ulong   Y          = ExpByModule.Exponentiation(y, k, p);

            for (int i = 0; i < CodedLineLength; ++i)
            {
                CypherText[i] = (CodedLine[i] * Y) % p;
            }
            return(CypherText);
        }
Beispiel #10
0
        public ulong[] Decryption(ulong[] CypherText)
        {
            int CypherTextLength = CypherText.Length;

            ulong[] OpenText  = new ulong[CypherTextLength];
            ulong   reverse_a = ExpByModule.Exponentiation(a, p - 1 - x, p);

            for (int i = 0; i < CypherTextLength; ++i)
            {
                OpenText[i] = (CypherText[i] * reverse_a) % p;
            }
            return(OpenText);
        }
Beispiel #11
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 = "Цифровая подпись не действительна";
            }
        }
Beispiel #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool Is_p_prime = IsPrime.Check(P);

            if (!Is_p_prime)
            {
                if (!Is_p_prime)
                {
                    MessageBox.Show("Число P не простое", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                ulong[]      RandomStorage;
                List <ulong> Random = new List <ulong>();
                for (ulong i = 3; i < P / 2; ++i)
                {
                    if (0 == (P - 1) % i && IsPrime.Check(i))
                    {
                        Random.Add(i);
                    }
                }
                RandomStorage = Random.ToArray();
                Random rand = new Random();
                Q = RandomStorage[rand.Next(0, RandomStorage.Length)];

                ulong[]      RandomStorage2;
                List <ulong> Random2 = new List <ulong>();
                for (ulong i = 1; i < P - 1; ++i)
                {
                    if (1 == ExpByModule.Exponentiation(i, Q, P))
                    {
                        Random2.Add(i);
                    }
                }
                RandomStorage2 = Random2.ToArray();
                Random rand2 = new Random();
                A = RandomStorage2[rand2.Next(0, RandomStorage2.Length)];

                Random rand3 = new Random();
                SecretKey = (ulong)rand3.Next(1, (int)Q - 1);
                OpenKey   = ExpByModule.Exponentiation(A, SecretKey, P);
            }
        }
Beispiel #13
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;
        }
Beispiel #14
0
 private void getSignature_Click(object sender, EventArgs e)
 {
     Signature = ExpByModule.Exponentiation(HidedMessage, SecretKey, P * Q);
 }
Beispiel #15
0
 public ulong GetFirstCypherPart()
 {
     a = ExpByModule.Exponentiation(g, k, p);
     return(a);
 }
Beispiel #16
0
 public ulong GetOpenKey()
 {
     y = ExpByModule.Exponentiation(g, x, p);
     return(y);
 }
Beispiel #17
0
 private void getKey_Click(object sender, EventArgs e)
 {
     Key = ExpByModule.Exponentiation(RecievedMessage, X, P);
 }
Beispiel #18
0
 private void calculateSendedMessage_Click(object sender, EventArgs e)
 {
     SendedMessage = ExpByModule.Exponentiation(A, X, P);
 }
Beispiel #19
0
 private void getKey_Click(object sender, EventArgs e)
 {
     Key = (ExpByModule.Exponentiation(RecievedMessage, B, P) * ExpByModule.Exponentiation(RecievedZ, Y, P)) % P;
 }