【问题标题】:C# modPow negative exponent trickC# modPow 负指数技巧
【发布时间】:2013-10-09 09:35:54
【问题描述】:

我尝试使用 using System.Numerics.BigInteger; 并使用负指数执行 modPow,我阅读了有关 Exception 的文档,这就是我做了一些技巧的原因

//a^(-x) mod n == (a^(-1))^x mod n
BigInteger tmp = BigInteger.ModPow(BigInteger.Divide(BigInteger.One, a), 
                 secretKey, pCommon);
BigInteger resBigInteger = BigInteger.Multiply(b, tmp); 

但是 tmp 为 0。我该如何解决这个问题?

【问题讨论】:

    标签: c# biginteger modulo pow


    【解决方案1】:

    你的“伎俩”只是在自欺欺人。 BigInteger.Divide(BigInteger.One, a) 几乎总是零,除非 a 为 1。无论如何,这不是计算模逆的方法。您必须实现扩展欧几里得算法,或者,如果您有 pCommon 的完整分解,您可以计算 aΦ(pCommon) - 1 == a-1 mod pCommon,其中 Φ(n) 是 euler totient function

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-17
      • 2010-10-13
      • 2011-11-20
      • 2011-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 1970-01-01
      相关资源
      最近更新 更多