Example #1
0
def share_string_to_point(share_string, charset):
    """ Convert a share string to a point (a tuple of integers).
    """
    # share should be in the format "01-d051080de7..."
    if '-' in charset:
        raise ValueError(
            'The character "-" cannot be in the supplied charset.')
    if not isinstance(share_string, str) and share_string.count('-') == 1:
        raise ValueError('Share format is invalid.')
    x_string, y_string = share_string.split('-')
    if (set(x_string) - set(charset)) or (set(y_string) - set(charset)):
        raise ValueError("Share has characters that aren't in the charset.")

    if (isinstance(x_string, bytes)):
        temp = str(x_string)
        x_string = ""
        for i in range(2, len(temp) - 1):
            x_string += temp[i]

    if (isinstance(y_string, bytes)):
        temp = str(y_string)
        y_string = ""
        for i in range(2, len(temp) - 1):
            y_string += temp[i]

    x = charset_to_int(x_string, charset)
    y = charset_to_int(y_string, charset)
    return (x, y)
Example #2
0
def share_string_to_point(share_string, charset):
    """ Convert a share string to a point (a tuple of integers).
    """
    # share should be in the format "01-d051080de7..."
    if '-' in charset:
        raise ValueError(
            'The character "-" cannot be in the supplied charset.')
    if not isinstance(share_string, str) and share_string.count('-') == 1:
        raise ValueError('Share format is invalid.')
    x_string, y_string = share_string.split('-')
    if (set(x_string) - set(charset)) or (set(y_string) - set(charset)):
        raise ValueError("Share has characters that aren't in the charset.")
    x_val = charset_to_int(x_string, charset)
    y_val = charset_to_int(y_string, charset)
    return (x_val, y_val)
Example #3
0
def share_string_to_point(share_string, charset):
    """ Convert a share string to a point (a tuple of integers).
    """
    # share should be in the format "01-d051080de7..."
    if '-' in charset:
        raise ValueError(
            'The character "-" cannot be in the supplied charset.')
    if not isinstance(share_string, str) and share_string.count('-') == 1:
        raise ValueError('Share format is invalid.')
    x_string, y_string = share_string.split('-')
    if (set(x_string) - set(charset)) or (set(y_string) - set(charset)):
        raise ValueError("Share has characters that aren't in the charset.")
    x = charset_to_int(x_string, charset)
    y = charset_to_int(y_string, charset)
    return (x, y)
Example #4
0
 def split_secret(cls, secret_string, share_threshold, num_shares):
     secret_int = charset_to_int(secret_string, cls.secret_charset)
     points = secret_int_to_points(secret_int, share_threshold, num_shares)
     shares = []
     for point in points:
         shares.append(point_to_share_string(point, cls.share_charset))
     return shares
Example #5
0
 def split_secret(cls, secret_string, share_threshold, num_shares):
     secret_int = charset_to_int(secret_string, cls.secret_charset)
     points = secret_int_to_points(secret_int, share_threshold, num_shares)
     shares = []
     for point in points:
         shares.append(point_to_share_string(point, cls.share_charset))
     return shares
Example #6
0
 def _generate_and_record_params_for_secret(self, secret_string,
                                            share_threshold, max_shares):
     secret_int = charset_to_int(secret_string, self.secret_charset)
     prime = get_large_enough_prime([secret_int, max_shares])
     coefficients = random_polynomial(share_threshold - 1, secret_int,
                                      prime)
     self._record_params_for_secret(secret_string, secret_int, prime,
                                    coefficients)
Example #7
0
 def split_secret_get_shares_and_modulus(cls, secret_string,
                                         share_threshold, num_shares):
     secret_int = charset_to_int(secret_string, cls.secret_charset)
     prime = get_large_enough_prime([secret_int, num_shares])
     points = secret_int_to_points(secret_int, share_threshold, num_shares,
                                   prime)
     shares = []
     for point in points:
         shares.append(point_to_share_string(point, cls.share_charset))
     return (shares, prime)
Example #8
0
 def split_secret(cls, secret_string, share_threshold, num_shares):
     if (isinstance(secret_string, bytes)):
         temp = str(secret_string)
         secret_string = ""
         for i in range(2, len(temp) - 1):
             secret_string += temp[i]
     secret_int = charset_to_int(secret_string, cls.secret_charset)
     points = secret_int_to_points(secret_int, share_threshold, num_shares)
     shares = []
     for point in points:
         shares.append(point_to_share_string(point, cls.share_charset))
     return shares
Example #9
0
    def split_secret(cls, secret_string, share_threshold, num_shares):
        secret_int = charset_to_int(secret_string, cls.secret_charset)
        points = secret_int_to_points(secret_int, share_threshold, num_shares)
        shares = []
        for point in points:
            shares.append(point_to_share_string(point, cls.share_charset))

        recovered = cls.recover_secret(shares)
        if secret_string != recovered:
            raise ValueError(
                'Shares did not recover secret. Check that secret does not begin with "{}"'
                .format(cls.secret_charset[0]))
        return shares
Example #10
0
 def test_deadbeef_to_int(self):
     s = "deadbeef"
     value = charset_to_int(s, base16_chars)
     reference_value = int(s, 16)
     self.assertEqual(value, reference_value)
Example #11
0
 def split_secret(cls, secret_string, share_threshold, num_shares):
     secret_int = charset_to_int(secret_string, cls.secret_charset)
     points = secret_int_to_points(secret_int, share_threshold, num_shares)
     point_to_share_fn = rpartial(point_to_share_string, cls.share_charset)
     return lmap(point_to_share_fn, points)
Example #12
0
 def split_secret(cls, secret_string, share_threshold, num_shares):
     secret_int = charset_to_int(secret_string, cls.secret_charset)
     points = secret_int_to_points(secret_int, share_threshold, num_shares)
     return cls.points_to_shares(points)