Python zfec howto/example

To install

$ pip install zfec

Suppose I have two blocks of data and want a third block as redundancy

>>> zfec.Encoder(2, 3).encode(['ab', 'cd'])
['ab', 'cd', 'en']
>>> zfec.Decoder(2, 3).decode(['ab', 'cd', ], [0, 1])
['ab', 'cd']
# somehow lost the second block, use the third block the recover
>>> zfec.Decoder(2, 3).decode(['ab', 'en', ], [0, 2])
['ab', 'cd']

In the above example, k=2 and m=3


btw Trivial secret sharing

secret = 123
a, b, c = [int((random.random() * 256)) for x in range(3)]
d = map(xor, [secret, a, b, c])

so 4 players has each a share of secret.

This is kinda lame... Shamir's scheme is much better