예제 #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], integer_types) and isinstance(point[1], integer_types)):
        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
예제 #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
예제 #3
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
예제 #4
0
 def recover_secret(cls, shares, prime=None):
     if not prime:
         warnings.warn(
             "Trying to recover secret without knowing the modulus! This might fail!"
         )
     points = []
     for share in shares:
         points.append(share_string_to_point(share, cls.share_charset))
     secret_int = points_to_secret_int(points, prime)
     secret_string = int_to_charset(secret_int, cls.secret_charset)
     return secret_string
예제 #5
0
 def test_long_to_hex(self):
     i = int("985936198705846800453632448571546073741637651923621735932"
             "00564555477131708560")
     reference_value = hex(i).rstrip('L').lstrip('0x')
     value = int_to_charset(i, base16_chars)
     self.assertEqual(value, reference_value)
예제 #6
0
 def test_int_to_deadbeef(self):
     i = 3735928559
     reference_value = ("%x" % i).replace('0x', '')
     value = int_to_charset(i, base16_chars)
     self.assertEqual(value, reference_value)