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.")
    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 = charset_to_int(x_string, charset)
    y = charset_to_int(y_string, charset)
    return (x, y)
Example #3
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 #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