# Copyright 2014 Chris Kuethe import StringIO from pysssslib import s4_encode, s4_decode inputstr = StringIO.StringIO("secret12345") num_shares = 5 num_needed = 3 exitcode = 0 # try this with 0 and 1 incorrect fragments... for num_bad in range(2): shares = [] for i in xrange(num_shares): shares.append(StringIO.StringIO()) s4_encode(inputstr,shares,num_needed) # construct an incorrect fragment by reversing the first fragment if num_bad: wrong = shares[0].getvalue().encode('hex') wrong = wrong[::-1] wrong = wrong.decode('hex') shares.append(StringIO.StringIO()) shares[-1].write(wrong) # test all-fragments (5), over-determined (4), sufficient (3), insufficient (2) while True: i = len(shares) if ((i - num_bad) < (num_needed - 1)): break
# # -*- coding: utf-8 -*- from pysssslib import s4_encode, s4_decode if __name__ == "__main__": import StringIO input = StringIO.StringIO("Too many secrets, Marty!") outputs = [] n = 10 k = 4 for i in xrange(n): outputs.append(StringIO.StringIO()) s4_encode(input, outputs, k) print "output shares %d-of-%d" % (k, n) for i in xrange(n): print str(i) + ": " + outputs[i].getvalue().encode("hex") print "" print "randomly selecting %d shares" % k import random inputs = [] randIndex = random.sample(range(n), k) for i in randIndex: f = outputs[i] s = f.getvalue().encode("hex") print str(i) + ": " + s
# limitations under the License. # # -*- coding: utf-8 -*- from pysssslib import s4_encode, s4_decode if __name__ == "__main__": import StringIO input = StringIO.StringIO("Too many secrets, Marty!") outputs = [] n = 10 k = 4 for i in xrange(n): outputs.append(StringIO.StringIO()) s4_encode(input,outputs,k) print "output shares %d-of-%d" % (k, n) for i in xrange(n): print str(i)+": "+outputs[i].getvalue().encode('hex') print "" print "randomly selecting %d shares" % k import random inputs = [] randIndex = random.sample(range(n), k) for i in randIndex: f = outputs[i] s = f.getvalue().encode('hex') print str(i)+": "+s inputs.append(f)