BigInt powmod(b, e, m) or equivalent

i asked this question on the google list last year (July 2018) and got no response, so I’ll ask here again on the new forum.

I’m converting Ruby -> Crystal.

In the Ruby OPENSSL library, when I ‘require openssl’ I can then use a bunch of fast modular math methods like.

y = b.to_bn.mod_exp(d, self)

In Crystal I have to do

def powmod(b, x, m)        
  r = 1.to_big_i; b = b.to_big_i        
  while x > 0          
    r = (r * b) % m if x.odd?          
    b = (b * b) % m          
    x >>= 1        

y = powmod(b, d, self)       # y = (b**d) mod self`

Does Crystal have the equivalent methods as Ruby (docs don’t show them)?

Will it provide in std libs these modular math function that exist in Ruby in the future?

Please open an issue in the GitHub tracker. It seems there’s a function to that in libgmp, which is what we are using for big numbers:

You can request or even try sending PRs for any functions that we didn’t include in the libgmp wrapper.