Class: ElGamal::PrivateKey
- Inherits:
-
Object
- Object
- ElGamal::PrivateKey
- Defined in:
- lib/elgamal/private_key.rb
Instance Attribute Summary collapse
-
#private_a ⇒ Object
readonly
Returns the value of attribute private_a.
Instance Method Summary collapse
- #decrypt(ciphertext) ⇒ Object
-
#initialize(private_a: nil, public_p: nil) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
Constructor Details
#initialize(private_a: nil, public_p: nil) ⇒ PrivateKey
7 8 9 10 |
# File 'lib/elgamal/private_key.rb', line 7 def initialize(private_a: nil, public_p: nil) @private_a = private_a @public_p = public_p end |
Instance Attribute Details
#private_a ⇒ Object (readonly)
Returns the value of attribute private_a.
5 6 7 |
# File 'lib/elgamal/private_key.rb', line 5 def private_a @private_a end |
Instance Method Details
#decrypt(ciphertext) ⇒ Object
12 13 14 15 |
# File 'lib/elgamal/private_key.rb', line 12 def decrypt(ciphertext) raise ArgumentError unless ciphertext.instance_of? Ciphertext ciphertext[1] * (ciphertext[0].to_bn.mod_exp(@private_a, @public_p)).mod_inverse(@public_p) % @public_p end |