Beispiel #1
0
def test_random():
    r = random.Random(0)
    x = bytearray(r.randrange(0, 256) for i in range(16 * 1024))
    y = ecc.encode(x)
    x_ = concat(ecc.decode(y))
    assert x_[: len(x)] == x
    assert all(v == 0 for v in x_[len(x) :])
Beispiel #2
0
def decode(bits_iterator):
    import bitarray
    import ecc

    def blocks():
        while True:
            bits = itertools.islice(bits_iterator, 8 * ecc.BLOCK_SIZE)
            block = bitarray.bitarray(endian='little')
            block.extend(bits)
            if not block:
                break
            yield bytearray(block.tobytes())

    return ecc.decode(blocks())
Beispiel #3
0
def test_file():
    data = open("data.send").read()
    enc = ecc.encode(data)
    assert concat(ecc.decode(enc)) == data