From 093d73e0a6427343c54fe807e8bd44ad7a3e75dd Mon Sep 17 00:00:00 2001 From: PaJa Date: Tue, 5 May 2015 22:03:48 +0200 Subject: [PATCH 1/2] Add test wit text and hex starting with zero --- tests/unit_tests.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/unit_tests.py b/tests/unit_tests.py index 585f2db..6a96a98 100644 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -29,10 +29,18 @@ def split_and_recover_secret(self, sharer_class, m, n, secret): def test_hex_to_hex_sharing(self): recovered_secret = self.split_and_recover_secret(SecretSharer, 3, 5, "c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a") + + def test_hex_with_zero_to_hex_sharing(self): + recovered_secret = self.split_and_recover_secret(SecretSharer, 3, 5, + "000ac4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a") def test_printable_ascii_to_hex_sharing(self): recovered_secret = self.split_and_recover_secret(PlaintextToHexSecretSharer, 3, 5, "correct horse battery staple") + + def test_printable_with_zero_ascii_to_hex_sharing(self): + recovered_secret = self.split_and_recover_secret(PlaintextToHexSecretSharer, 3, 5, + "000correct horse battery staple") def test_b58_to_b32_sharing(self): recovered_secret = self.split_and_recover_secret(BitcoinToB32SecretSharer, 3, 5, From a0e7bfef21a2f4a2e7d41644767311069b058f39 Mon Sep 17 00:00:00 2001 From: 0xF15E Date: Thu, 7 May 2015 23:19:32 +0200 Subject: [PATCH 2/2] Fix for conversion bug. --- secretsharing/charset.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/secretsharing/charset.py b/secretsharing/charset.py index af5b9fd..d7697e3 100644 --- a/secretsharing/charset.py +++ b/secretsharing/charset.py @@ -21,7 +21,7 @@ def int_to_charset(x, charset): x, digit = divmod(x, len(charset)) output += charset[digit] # reverse the characters in the output and return - return output[::-1] + return output def charset_to_int(s, charset): """ Turn a string into a non-negative integer. @@ -31,8 +31,10 @@ def charset_to_int(s, charset): if (set(s) - set(charset)): raise ValueError("s has chars that aren't in the charset.") output = 0 + i=0 for char in s: - output = output * len(charset) + charset.index(char) + output = output + (len(charset)**i)*charset.index(char) + i+=1 return output def change_charset(s, original_charset, target_charset):