elgamal 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f9c287446374f1cfbdb1b9d667d89f9353584e9
4
- data.tar.gz: 424a3efad80adea5ad4fe886ec09bbf78ce2a73e
3
+ metadata.gz: 22b5e8c5238b1b9b8658502e29bfc32f1d36559c
4
+ data.tar.gz: fb29043c6c400695887eb8a931004c5b7fba678b
5
5
  SHA512:
6
- metadata.gz: 1c0932d0d1b83dc9d478e3bb9d02d2725bb7e10c49cba6e287760606aa5036117375df002ad082bca0e940fa951b6e7058d43da84bf5f1351e1779b4de857b76
7
- data.tar.gz: 8253c0d3823c70cc5208f0bf8e28aacf5c7085e3ca9b45b70448119ca44b448dfd0653f0e1f33531b855d4c2f74d3c04fe18824184c3fdaab135a3f126ca6fbe
6
+ metadata.gz: 0a3903ab12acb477a22549a7e9b256ea89971f4dd2ec11a61cb5a1c582f4033442948f8f164a3daf2448c6dc8d7cb2a055ef96c2dd2663e97ef28b0f909da27c
7
+ data.tar.gz: 730d116036dd4dbd4cd8227a6f526aa254732d25771fd2a3eb57de9714890dd4a1df3639d92f424da497c396e6566e62f0b3e69ab5cd4faa100f1cc140d27402
@@ -7,8 +7,10 @@ module ElGamal
7
7
  @ciphertext = ciphertext
8
8
  end
9
9
 
10
+ attr_accessor :ciphertext
11
+
10
12
  def to_s
11
- "#{@ciphertext}"
13
+ @ciphertext.to_s
12
14
  end
13
15
 
14
16
  def [](pos)
@@ -7,10 +7,10 @@ module ElGamal
7
7
  @private_key = private_key
8
8
  end
9
9
 
10
- def generate(bits: 20)
10
+ def generate(bits: 20, a: nil)
11
11
  p = OpenSSL::BN::generate_prime(bits).to_i
12
12
  g = (rand * p).to_i
13
- a = (rand * (p - 1)).to_i + 1
13
+ a ||= (rand * (p - 1)).to_i + 1
14
14
  h = g.to_bn.mod_exp(a, p).to_i
15
15
  return ElGamal::PublicKey.new(public_p: p, public_g: g, public_h: h),
16
16
  ElGamal::PrivateKey.new(private_a: a, public_p: p)
@@ -12,8 +12,8 @@ module ElGamal
12
12
  @public_h = public_h
13
13
  end
14
14
 
15
- def encrypt(message)
16
- rand_k = rand(@public_p - 1) + 1
15
+ def encrypt(message, rand_k: nil)
16
+ rand_k ||= rand(@public_p - 1) + 1
17
17
  element_a = @public_g.to_bn.mod_exp(rand_k, @public_p).to_i
18
18
  element_b = message * @public_h.to_bn.mod_exp(rand_k, @public_p).to_i % @public_p
19
19
  return ElGamal::Ciphertext.new([element_a, element_b])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elgamal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Scarfone
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  version: '0'
42
42
  requirements: []
43
43
  rubyforge_project:
44
- rubygems_version: 2.5.1
44
+ rubygems_version: 2.5.2
45
45
  signing_key:
46
46
  specification_version: 4
47
47
  summary: Basic ruby ElGamal implementation.