Class: SecretSharing::Share

Inherits:
Object
  • Object
show all
Defined in:
lib/secret_sharing/share.rb

Overview

A share is an object that encapsulates the properties of a share created by Shamir's Secret Sharing algorithm.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(point) ⇒ Share

Create a share object

Example

point = SecretSharing::Point.new 1, 2
SecretSharing::Share.new point
# => #<SecretSharing::Share:0x0000000 @point=...>

Parameters:


17
18
19
# File 'lib/secret_sharing/share.rb', line 17

def initialize(point)
  @point = point
end

Instance Attribute Details

#pointSecretSharing::Point (readonly)

Returns Point the share was instantiated with

Returns:


6
7
8
# File 'lib/secret_sharing/share.rb', line 6

def point
  @point
end

Class Method Details

.from_string(share_string) ⇒ SecretSharing::Share

Creates a share object from its string representation.

Example

SecretSharing::Share.from_string "1-2"
# => #<SecretSharing::Share:0x0000000 @point=...>

Parameters:

  • share_string (String)

Returns:


42
43
44
45
46
# File 'lib/secret_sharing/share.rb', line 42

def self.from_string(share_string)
  x_string, y_string = share_string.split '-'
  point = Point.new x_string.to_i, y_string.to_i(16)
  new(point)
end

Instance Method Details

#to_s(x_length) ⇒ Object

A string representation of a share.

Example

point = SecretSharing::Point.new 1, 2
SecretSharing::Share.new(point).to_s
# => "1-2"

29
30
31
# File 'lib/secret_sharing/share.rb', line 29

def to_s(x_length)
  "#{point.x.to_s.rjust(x_length, '0')}-#{point.y.to_s(16)}"
end