Пример #1
0
        public Keys GetKeys()
        {
            ulong n     = p * q;
            ulong Eiler = (p - 1) * (q - 1);
            ulong OpenKey;

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

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

            for (ulong i = RandomRange; i <= Eiler; ++i)
            {
                if (1 == Euclid.FindGSD(i, Eiler))
                {
                    Random.Add(i);
                }
            }
            RandomStorage = Random.ToArray();
            Random rand = new Random();

            OpenKey = RandomStorage[rand.Next(0, RandomStorage.Length)];
            ulong SecretKey = ExtendedEuclid.FindReverse(OpenKey, Eiler);
            Keys  keys      = new Keys();

            keys.openKey   = OpenKey;
            keys.secretKey = SecretKey;
            return(keys);
        }
Пример #2
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;
        }
Пример #3
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;
        }