Exemplo n.º 1
0
def shamir_test(l, m, n):
	s = Shamir('english')
	seed = "Shamir's Secret Sharing Scheme!"[:l] # take first l characters
	shares = s.split(seed, m, n)
	print('original:', seed)
	print('shares:')
	for i in range(len(shares)):
		print('%2d :' % (i + 1), shares[i])
	shares = shares[:m] # take first m shares
	cmb = s.combine(shares)
	print ('combined:', cmb)
	if seed == cmb:
		print('TEST OK')
		print()
	else:
		print('TEST FAILED !!!')
		sys.exit(1)
Exemplo n.º 2
0
def shamir_test(l, m, n):
    s = Shamir('english')
    seed = "Shamir's Secret Sharing Scheme!"[:l]  # take first l characters
    shares = s.split(seed, m, n)
    print('original:', seed)
    print('shares:')
    for i in range(len(shares)):
        print('%2d :' % (i + 1), shares[i])
    shares = shares[:m]  # take first m shares
    cmb = s.combine(shares)
    print('combined:', cmb)
    if seed == cmb:
        print('TEST OK')
        print()
    else:
        print('TEST FAILED !!!')
        sys.exit(1)
Exemplo n.º 3
0
    l = [0 for i in range(0, word_count)]
    l[0] = nb >> word_size * (word_count - 1)

    for i in range(1, word_count):
        l[i] = (nb - special_sum(l[0:i])) >> ((word_count - i - 1) * word_size)
    return l


key = list(map(lambda x: wordlist.index(x), key))
nb = get_integer_from_key(key)
checksum = get_checksum(nb)

rec = (nb << 4) + checksum
print(to_list_of_ints(rec, 132, 11))

shares = Shamir.split(t, n, nb)
shares = [
    to_list_of_ints((share[1]._value << 4) + get_checksum(share[1]._value),
                    132, 11) for share in shares
]
print([[wordlist[index_word] for index_word in share] for share in shares])

# reconstruction
print("reconstruction:")
rec = [(i + 1, get_integer_from_key(shares[i])) for i in range(0, len(shares))]
reconstructed = Shamir.combine(rec)._value
reconstructed_final_int = (reconstructed << 4) + get_checksum(reconstructed)
l = to_list_of_ints(reconstructed_final_int, 132, 11)
print([wordlist[l[i]] for i in range(0, len(l))])