Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/schnorr.rb
Instance Method Summary collapse
- #method_missing(method, *args) ⇒ Object
-
#mod_pow(x, y) ⇒ Object
alternative implementation of Integer#pow for ruby 2.4 and earlier.
- #to_hex ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
126 127 128 129 |
# File 'lib/schnorr.rb', line 126 def method_missing(method, *args) return mod_pow(args[0], args[1]) if method == :pow && args.length < 3 super end |
Instance Method Details
#mod_pow(x, y) ⇒ Object
alternative implementation of Integer#pow for ruby 2.4 and earlier.
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/schnorr.rb', line 132 def mod_pow(x, y) return self ** x unless y b = self result = 1 while x > 0 result = (result * b) % y if (x & 1) == 1 x >>= 1 b = (b * b) % y end result end |
#to_hex ⇒ Object
121 122 123 124 |
# File 'lib/schnorr.rb', line 121 def to_hex hex = to_s(16) hex.rjust((hex.length / 2.0).ceil * 2, '0') end |