當前位置: 首頁>>代碼示例>>C#>>正文


C# mpz_t.Power方法代碼示例

本文整理匯總了C#中Mpir.NET.mpz_t.Power方法的典型用法代碼示例。如果您正苦於以下問題:C# mpz_t.Power方法的具體用法?C# mpz_t.Power怎麽用?C# mpz_t.Power使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mpir.NET.mpz_t的用法示例。


在下文中一共展示了mpz_t.Power方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: HandleResponse

        /// <summary>
        /// Generates the key after a response is received.
        /// </summary>
        /// <param name="response">The string representation of the response.</param>
        public void HandleResponse(byte[] response)
        {
            var currentPlatform = OSCheck.RunningPlatform ();
            if (currentPlatform == OSCheck.Platform.Mac) {
                throw new PlatformNotSupportedException ("Mac OSX is not a supported operating system for this.");
            }
            if (currentPlatform == OSCheck.Platform.Windows) {
                var B = new mpz_t (response, 1);

                S = B.Power (a);
                S = (S as mpz_t).Mod ((p as mpz_t));
                W_GetKeyData ();
            } else if (currentPlatform == OSCheck.Platform.Linux) {
                var B = new Integer (response);
                S = B.Pow (a);
                S %= p;
                L_GetKeyData ();
            }
        }
開發者ID:gitter-badger,項目名稱:LightNet,代碼行數:23,代碼來源:DiffieHellman.cs

示例2: GenerateResponse

        /// <summary>
        /// Generate a response packet.
        /// </summary>
        /// <param name="request">The string representation of the request.</param>
        /// <returns></returns>
        public byte[] GenerateResponse(byte[] request)
        {
            var currentPlatform = OSCheck.RunningPlatform ();
            if (currentPlatform == OSCheck.Platform.Mac) {
                throw new PlatformNotSupportedException ("Mac OSX is not a supported operating system for this.");
            }

            var instream = new MemoryStream (request);
            var gData = DataUtility.ReadBytesFromStream (instream);
            var pData = DataUtility.ReadBytesFromStream (instream);
            var AData = DataUtility.ReadBytesFromStream (instream);
            byte[] BData = null;

            if (currentPlatform == OSCheck.Platform.Windows) {
                g = new mpz_t (gData, 1);
                p = new mpz_t (pData, 1);
                var A = new mpz_t (AData, 1);

                // Generate the parameters.
                a = RandomGenerator.Next (bytes);
                var B = g.Power (a);
                B = B.Mod (p);

                // Get Raw IntX Data
                BData = B.ToByteArray (1);

                // Got the key!!! HOORAY!
                S = A.Power (a);
                S = S.Mod (p);
                W_GetKeyData ();
            } else if (currentPlatform == OSCheck.Platform.Linux) {
                g = new Integer ();
                g.FromBytes (gData);
                p = new Integer ();
                p.FromBytes (pData);
                var A = new Integer (AData);

                // Generate the parameters.
                a = RandomGenerator.Next (bytes);
                var B = g.Pow (a);
                B %= p;

                // Get Raw IntX Data
                BData = B.ToBytes ();

                // Got the key!!! HOORAY!
                S = A.Pow (a);
                S %= p;
                L_GetKeyData ();
            }
            return BData;
        }
開發者ID:gitter-badger,項目名稱:LightNet,代碼行數:57,代碼來源:DiffieHellman.cs


注:本文中的Mpir.NET.mpz_t.Power方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。