るりまサーチ

最速Rubyリファレンスマニュアル検索!
84件ヒット [1-84件を表示] (0.218秒)
トップページ > 種類:インスタンスメソッド[x] > クエリ:n[x] > クエリ:a[x] > クラス:OpenSSL::BN[x]

別のキーワード

  1. etc sc_xopen_enh_i18n
  2. rsa n
  3. rsa n=
  4. openssl n
  5. openssl n=

ライブラリ

キーワード

検索結果

OpenSSL::BN#negative? -> bool (12202.0)

自身が負である場合に true を返します。Ruby 2.5, OpenSSL 2.1.0 から利用できます。

...自身が負である場合に true を返します。Ruby 2.5, OpenSSL 2.1.0 から利用できます。

//emlist[][ruby]{
require 'openssl'
p 15.to_bn.negative? # => false
p 0.to_bn.negative? # => false
p (-5).to_bn.negative? # => true
//}...

OpenSSL::BN#clear_bit!(n) -> self (9243.0)

自身の n ビット目を0にします。

...自身の n ビット目を0にします。

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

a
= OpenSSL::BN.new("129")
a
.clear_bit!(0)
a
# => 128
//}

@param n 0にするビットの位置
@raise OpenSSL::BNError 計算時エラー
@see OpenSSL::set_bit!...

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

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

... n ビットでマスクし、破壊的に変更します。

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_add(other, m) -> OpenSSL::BN (9202.0)

(self + other) % m を返します。

...(self + other) % m を返します。

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

OpenSSL::BN
.new("7").mod_add(OpenSSL::BN.new("3"), OpenSSL::BN.new("6")) # => 4
//}

@param other 和を取る数
@param m 剰余を取る数
@raise OpenSSL::BNError 計算時エラー...

OpenSSL::BN#prime_fasttest?(checks=nil, vtrivdiv=true) -> bool (9202.0)

自身が素数であるなら true を返します。

...である場合には、 Miller-Rabin 法での
判定の前に小さな素数で割ることで素数か否かを
調べます。自身が小さな素数である場合にはこの手順
により素数ではないと誤った返り値を返します。

Miller-Rabin 法により確率的に判定...
...checksがnilである場合は OpenSSL が適切な
回数を判断します。

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

# 181 は 「小さな素数」である
OpenSSL::BN
.new("181").prime_fasttest?(nil, true) # => false
OpenSSL::BN
.new("181").prime_fasttest?(nil, false) # => true
//}

@param checks...
...Miller-Robin法の繰り返しの回数
@param vtrivdiv 真なら小さな素数で割ることでの素数判定を試みます
@raise OpenSSL::BNError 判定時にエラーが発生
@see OpenSSL::BN#prime?...

絞り込み条件を変える

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

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

...す。

base で、変換方法(基数)を指定します。
デフォルトは 10 で、他に 16, 2, 0 を指定できます。

10 10進数の表記
16 16進数の表記
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...
...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#set_bit!(n) -> self (3143.0)

自身の n ビット目を1にします。

...自身の n ビット目を1にします。

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

a
= OpenSSL::BN.new("128")
a
.set_bit!(0)
a
# => 129
//}

@param n 1にするビットの位置
@raise OpenSSL::BNError 計算時エラー
@see OpenSSL::clear_bit!, OpenSSL::bit_set?...

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

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

...ときに、自身を Integer のオブジェクトに
変換して [other, 変換後オブジェクト] にして返します。
それ以外の場合は例外 TypeError を発生させます。

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

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

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