🍗 Wiki

OpenSSL

OpenSSL

You don’t need to think deeply when you have to deal with big numbers in Python. By default Python can handle them just like the other numbers. It is one of wonderful features of Python.

But in Ruby, dealing with big numbers is a big thing. Even though there is a bignum feature in Ruby.

Ruby’s OpenSSL gem provides big number handling library.

OpenSSL library is a default gem of Ruby, you don’t need to install separately.

1. OpenSSL::BN

BN should mean an abbreviation of Big Number.

require 'openssl'

a_bn = OpenSSL::BN.new()
b_bn = OpenSSL::BN.new()

You can do arithmetic operations.

a_bn + b_bn

a_bn - b_bn

a_bn * b_bn

1.1. Modular Inverse

Ruby’s default pow() has limited features.