るりまサーチ

最速Rubyリファレンスマニュアル検索!
120件ヒット [1-100件を表示] (0.102秒)

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

Integer#to_bn -> OpenSSL::BN (18256.0)

Integer を同じ数を表す OpenSSL::BN のオブジェクトに 変換します。

...

//emlist[][ruby]{
require 'pp'
require 'openssl'

pp 5.to_bn #=> #<OpenSSL::BN 5>
pp (-5).to_bn #=> #<OpenSSL::BN -5>
//}

なお、実装は、以下のようになっています。

//emlist[][ruby]{
class Integer
def to_bn
OpenSSL::BN::new(self)
end
end
//}

@
see OpenSSL::BN.ne...
...ます。

//emlist[][ruby]{
require 'openssl'

pp 5.to_bn #=> #<OpenSSL::BN 5>
pp (-5).to_bn #=> #<OpenSSL::BN -5>
//}

なお、実装は、以下のようになっています。

//emlist[][ruby]{
class Integer
def to_bn
OpenSSL::BN::new(self)
end
end
//}

@
see OpenSSL::BN.new, Open...

OpenSSL::BN#to_s(base=10) -> String (221.0)

自身を表す文字列を返します。

...2 big-endianの符号無し整数のバイナリ列
0 MPI形式の文字列(バイト列)

@
param base 文字列への変換方法(基数)
@
raise OpenSSL::BNError 変換に失敗した場合に発生します

//emlist[][ruby]{
require 'openssl'

p 10.to_bn.to_s # => "10"
p (-5).to_bn.to_s...
...=> "-5"

p 0.to_bn.to_s(16) # => "0"
p 9.to_bn.to_s(16) # => "09"
p 10.to_bn.to_s(16) # => "0A"
p 16.to_bn.to_s(16) # => "10"
p 26.to_bn.to_s(16) # => "1A"
p 256.to_bn.to_s(16) # => "0100"

p 0.to_bn.to_s(2) # => ""
p 6.to_bn.to_s(2) # => "\x06"
p 7.to_bn.to_s(2) # => "\a"

p 0.to_bn.to_s(...
...0) # => "\x00\x00\x00\x00"
p 6.to_bn.to_s(0) # => "\x00\x00\x00\x01\x06"
p 7.to_bn.to_s(0) # => "\x00\x00\x00\x01\a"
//}

反対に、文字列から OpenSSL::BN クラスのインスタンスを作るには
OpenSSL::BN.new を用います。

@
see OpenSSL::BN.new...

OpenSSL::BN#<<(other) -> OpenSSL::BN (137.0)

自身を other ビット左シフトした値を返します。

...自身を other ビット左シフトした値を返します。

//emlist[][ruby]{
bn = 1.to_bn
pp bn << 1 # => #<OpenSSL::BN 2>
pp bn # => #<OpenSSL::BN 1>
//}

@
param other シフトするビット数
@
raise OpenSSL::BNError 計算時エラー
@
see OpenSSL::BN#lshift!...

OpenSSL::BN#>>(other) -> OpenSSL::BN (137.0)

自身を other ビット右シフトした値を返します。

...自身を other ビット右シフトした値を返します。

//emlist[][ruby]{
require 'openssl'

bn = 2.to_bn
bn >> 1 # => #<OpenSSL::BN 1>
bn # => #<OpenSSL::BN 2>
//}

@
param other シフトするビット数
@
raise OpenSSL::BNError 計算時エラー
@
see OpenSSL::BN#rshift!...

OpenSSL::BN#coerce(other) -> Array (137.0)

自身と other が同じクラスになるよう、自身か other を変換し [other, self] という配列にして返します。

...す。

//emlist[][ruby]{
require 'openssl'
p 1.to_bn.coerce(2) # => [2, 1]
//}

@
param other 変換の基準となるオブジェクト
@
raise TypeError 変換に失敗した場合に発生します

coerce メソッドの詳細な説明は、Numeric#coerce にあります。
@
see Numeric#coerce...

絞り込み条件を変える

OpenSSL::BN#lshift!(n) -> self (137.0)

自身を n ビット左シフトします。 OpenSSL::BN#<<と異なり、破壊的メソッドです。

...す。
OpenSSL::BN#<<と異なり、破壊的メソッドです。

//emlist[][ruby]{
require 'openssl'

bn = 1.to_bn
bn.lshift!(2) # => #<OpenSSL::BN 4>
bn # => #<OpenSSL::BN 4>
//}

@
param n シフトするビット数
@
raise OpenSSL::BNError 計算時エラー
@
see OpenSSL::BN#<<...

OpenSSL::BN#rshift!(n) -> self (137.0)

自身を n ビット右シフトします。 [[m:OpenSSL::BN#>>]と異なり、破壊的メソッドです。

...[[m:OpenSSL::BN#>>]と異なり、破壊的メソッドです。

//emlist[][ruby]{
require 'openssl'

bn = 8.to_bn
bn.rshift!(1) # => #<OpenSSL::BN 4>
bn # => #<OpenSSL::BN 4>
//}

@
param n シフトするビット数
@
raise OpenSSL::BNError 計算時エラー
@
see OpenSSL::BN#>>...

OpenSSL::BN#mask_bits!(n) -> self (131.0)

自身を下位 n ビットでマスクし、破壊的に変更します。

...合は例外 OpenSSL::BNError
が発生します。

//emlist[][ruby]{
require 'openssl'

bn = 0b1111_1111.to_bn

bn.mask_bits!(8)
p "%b" % bn # => "11111111"

bn.mask_bits!(3)
p "%b" % bn # => "111"
//}

@
param n マスクするビット数
@
raise OpenSSL::BNError 計算時エラー...

OpenSSL::BN#mod_inverse(m) -> OpenSSL::BN (131.0)

自身の mod m における逆元を返します。

...(self * r) % m == 1 となる r を返します。
存在しない場合は例外 OpenSSL::BNError が発生します。

//emlist[][ruby]{
require 'openssl'

p 3.to_bn.mod_inverse(5) # => 2
p (3 * 2) % 5 # => 1
//}

@
param m mod を取る数
@
raise OpenSSL::BNError 計算時エラー...
<< 1 2 > >>