예제 #1
0
 def test_encoding_large_strings(self):
     k = 3
     n = 5
     p = 2 ** 521 - 1  # 13th Mersenne prime
     string = 'This is a pretty long secret message. Big field order is needed.'
     integer = shamir.str_to_int(string)
     shares = shamir.encode(integer, k=k, n=n, p=p)
     recovered_integer = shamir.decode(shares, k=k, p=p)
     recovered_string = shamir.int_to_str(recovered_integer)
     self.assertEqual(string, recovered_string)
예제 #2
0
 def test_decoded_str_equals_original(self):
     k = 3
     n = 5
     p = 2 ** 61 - 1  # 9th Mersenne prime
     string = 'message'
     integer = shamir.str_to_int(string)
     shares = shamir.encode(integer, k=k, n=n, p=p)
     recovered_integer = shamir.decode(shares, k=k, p=p)
     recovered_string = shamir.int_to_str(recovered_integer)
     self.assertEqual(string, recovered_string)
예제 #3
0
 def decode_secret(self):
     k = int(self.edit_k.text())
     try:
         shares = self.string_to_shares(self.edit_shares.toPlainText())
         supplied_shares = len(shares)
         if supplied_shares < k:
             error_message = QErrorMessage(self)
             error_message.showMessage(
                 'zbyt mało fragmentów<br>'
                 'podano: {}<br>'
                 'wymagane: co najmniej {}'.format(supplied_shares, k))
             return
         secret = shamir.decode(shares, k=k, p=self.field_order)
         self.edit_secret.setText(shamir.int_to_str(secret))
     except Exception as e:
         print('exception:')
         print(e)
예제 #4
0
 def test_int_to_str_and_back(self):
     integer = 13
     string = shamir.int_to_str(integer)
     recovered_integer = shamir.str_to_int(string)
     self.assertEqual(integer, recovered_integer)
예제 #5
0
 def test_str_to_int_and_back(self):
     string = 'abc'
     integer = shamir.str_to_int(string)
     recovered_string = shamir.int_to_str(integer)
     self.assertEqual(string, recovered_string)
예제 #6
0
 def test_int_to_str_returns_str(self):
     integer = 5
     string = shamir.int_to_str(integer)
     self.assertIsInstance(string, str)