Exemple #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)
Exemple #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)
Exemple #3
0
    def calc_shares(self):
        try:
            secret = self.edit_secret.text()
            n = int(self.edit_n.text())
            k = int(self.edit_k.text())
            if k > n:
                error_message = QErrorMessage(self)
                error_message.showMessage('minimalna liczba fragmentów nie może być większa niż '
                                          'całkowita liczba fragmentów')
                return

            int_secret = shamir.str_to_int(secret)
            if int_secret >= self.field_order:
                error_message = QErrorMessage(self)
                error_message.showMessage('podany sekret jest zbyt długi')
                return
            shares = shamir.encode(int_secret, k=k, n=n, p=self.field_order)
        except ValueError:
            print('wrong values')
            return

        shares_string = self.shares_to_string(shares)
        self.edit_shares.setText(shares_string)
Exemple #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)
Exemple #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)
Exemple #6
0
 def test_str_to_int_returns_int(self):
     string = 'abc'
     integer = shamir.str_to_int(string)
     self.assertIsInstance(integer, int)