I know there is modular exponentiation [std.math.exponential.powmod](https://dlang.org/library/std/math/exponential/powmod.html) in the standard library.While it works great in Pyrhon (even with very large numbers), it doesn't work with signed numbers in D. That's why I turned to the alternative below. Don't let it be misunderstood, I don't want to wear out the D language, I use whatever I have, I love D and I don't ask why it works so strangely.

```d
//import std.math.exponential : fpowmod = powmod; /*
T fpowmod(T)(T base, T exponent, T modulus)
{
    auto r = T(1);
    for (T x = base, y = exponent; y;
        x = x * x % modulus, y /= 2)
        if (y % 2) r = r * x % modulus;

    return r;
}//*/
```

Thanks...

SDB@79

I have only one question: Is there a modInverse() function in the standard library for use in RSA? I did research on this subject within the relevant modules. I guess not these?

* [std.mathspecial.logmdigammaInverse](https://dlang.org/phobos/std_mathspecial.html) * [std.numeric.inverseFft](https://dlang.org/library/std/numeric.html)
  • modInverse & powMod Salih Dincer via Digitalmars-d-learn

Reply via email to