Esempio n. 1
0
def point_to_share_string(point, charset):
    """ Convert a point (a tuple of two integers) into a share string - that is,
        a representation of the point that uses the charset provided.
    """
    # point should be in the format (1, 4938573982723...)
    if '-' in charset:
        raise ValueError('The character "-" cannot be in the supplied charset.')
    if not isinstance(point, tuple) and len(point) == 2 and \
        isinstance(point[0], (int, long)) and isinstance(point[1], (int, long)):
        raise ValueError('Point format is invalid. Must be a pair of integers.')
    x,y = point
    x_string = int_to_charset(x, charset)
    y_string = int_to_charset(y, charset)
    share_string = x_string + '-' + y_string
    return share_string
Esempio n. 2
0
 def recover_secret(cls, shares):
     points = []
     for share in shares:
         points.append(share_string_to_point(share, cls.share_charset))
     secret_int = points_to_secret_int(points)
     secret_string = int_to_charset(secret_int, cls.secret_charset)
     return secret_string
Esempio n. 3
0
 def recover_secret(cls, shares):
     points = []
     for share in shares:
         points.append(share_string_to_point(share, cls.share_charset))
     secret_int = points_to_secret_int(points)
     secret_string = int_to_charset(secret_int, cls.secret_charset)
     return secret_string
Esempio n. 4
0
def point_to_share_string(point, charset):
    """ Convert a point (a tuple of two integers) into a share string - that is,
        a representation of the point that uses the charset provided.
    """
    # point should be in the format (1, 4938573982723...)
    if '-' in charset:
        raise ValueError(
            'The character "-" cannot be in the supplied charset.')
    if not isinstance(point, tuple) and len(point) == 2 and \
        isinstance(point[0], (int, long)) and isinstance(point[1], (int, long)):
        raise ValueError(
            'Point format is invalid. Must be a pair of integers.')
    x, y = point
    x_string = int_to_charset(x, charset)
    y_string = int_to_charset(y, charset)
    share_string = x_string + '-' + y_string
    return share_string