Example #1
0
    def encodeSolomonTest(self, l):
        k = len(l)  # must be <= kmax
        n = (3 * k) - (2 * self.rm)
        assert k <= self.kmax, "In encodeSolomon length of list must be less than or equal to kmax: "+self.kmax
        print "k: ", k, " n: ", n, " rm: ", self.rm
        rcodec = rdsolomonlib.Codec(n, k, self.rsymsize)
        rcodec2 = rdsolomonlib.Codec(n, k, self.rsymsize)
        #for decoding either rcodec or rcodec2 can be used.

        # exit()
        encoded = rcodec.encodechunks(l)
        print "encoded: ", encoded
        checksums = encoded[k:]  # this is the parity list
        print "checksum-parities: ", checksums
        decoded, corrections = rcodec.decodechunks(encoded)
        print "decoded: ", decoded
        assert cmpT(decoded, l) == True, " Cannot decode!"
        brokenl = list(encoded)
        brokenl = brokenl[0:k]
        random.shuffle(brokenl)
        brokenl = brokenl + list(checksums)
        for i in range(0, len(l) - self.rm):
        #for i in range(0, len(l)):
            print "i: ", i
            brokenl[i] = 'x' * 8
            broken = tuple(brokenl)
            print "broken: ", broken
            #decoded, corrections = rcodec.decodechunks(broken)
            ereasures = range(0,i+1)
            decoded, corrections = rcodec2.decodechunks(broken, ereasures)
            print "to-be-decoded: ", broken
            print "corrections: ", corrections
            assert cmpT(decoded, l)== True, "Cannot decode!"
            print "decoded[0:k]: ", decoded[0:k]
            print ""
Example #2
0
def tryone((encoded_len, data_len, symbol_size, gfpoly, fcr, prim, candidates,
            expecteds)):
    try:
        codec = reedsolomon.Codec(encoded_len, data_len, symbol_size, gfpoly,
                                  fcr, prim)
    except MemoryError, e:
        return
Example #3
0
 def decodeSolomon(self, data_part, k, checksum, n):
     encoded = tuple(data_part)+checksum
     assert k <= self.kmax, "In encodeSolomon length of list must be less than or equal to kmax: " + self.kmax
     #print "k: ", k, " n: ", n, " rm: ", self.rm
     rcodec = rdsolomonlib.Codec(n, k, self.rsymsize)
     decoded, corrections = rcodec.decodechunks(encoded)
     return (decoded, corrections)
Example #4
0
 def encodeSolomon(self, l, prune_extra = False):
     l2 = l
     k = len(l2)  # must be <= kmax
     if prune_extra and k > self.kmax:
         print "In encodeSolomon number of list: "+str(k)+ " must be less than or equal to kmax: " + str(self.kmax)
         print "That is why we are pruning extra points beginning from last. need a splitting solution!!"
         l2 = l[0:self.kmax]
         k = len(l2)
     if k > self.kmax:
         raise "In encodeSolomon number of list: "+str(k)+ " must be less than or equal to kmax: " + str(self.kmax)
     n = (3 * k) - (2 * self.rm)
     if n <= k:
         n = k*(self.rm)
     #print "k: ", k, " n: ", n, " rm: ", self.rm
     rcodec = rdsolomonlib.Codec(n, k, self.rsymsize)
     encoded = rcodec.encodechunks(l2)
     #print "encoded: ", encoded
     #checksums = list(encoded[k:])  # this is the parity list
     checksums = encoded[k:]  # this is the parity list
     return k, checksums, n # returns the data part length, and parity
Example #5
0
def main():
    c = reedsolomon.Codec(10, 8)

    data = (''.join([chr(i) for i in range(256)])) * 40961
    chunksize, remainder = divmod(len(data), c.k)
    if remainder:
        chunksize += 1
    chunks = []
    for i in range(c.k):
        chunk = data[chunksize * i:chunksize * (i + 1)]
        if len(chunk) < chunksize:
            chunk += '\0' * (chunksize - len(chunk))
        chunks.append(chunk)
    start = time.time()
    encoded = c.encodechunks(chunks)
    end = time.time()
    assert len(encoded) == c.n

    encoded_bytes = float(sum([len(s) for s in chunks]))
    encode_time = end - start

    start = time.time()
    decoded, corrections = c.decodechunks(encoded)
    end = time.time()
    assert not corrections
    assert len(decoded) == c.k
    assert (''.join(decoded))[:len(data)] == data

    decoded_bytes = float(sum([len(s) for s in encoded]))
    decode_time = end - start

    print c
    print 'encoded %0.2f MiB in %0.2f s (%0.2f MiB/s)' % (
        encoded_bytes / MiB, encode_time, encoded_bytes / MiB / encode_time)
    print 'decoded %0.2f MiB in %0.2f s (%0.2f MiB/s)' % (
        decoded_bytes / MiB, decode_time, decoded_bytes / MiB / decode_time)
Example #6
0
                   struct.pack('<q', int('srg00lgbif', 32))
                   + struct.pack('<q', int('4c6u07sq', 32))[:-3],
                   }),
        ),
    (12,  7, 8
        frozenset({struct.pack('>q', int('srg00lgbif', 32))[1:],
                   struct.pack('<q', int('srg00lgbif', 32))[:-1],
                   }),
        frozenset({struct.pack('>q', int('srg00lgbif', 32))[1:]
                   + struct.pack('>q', int('4c6u07sq', 32))[3:],
                   struct.pack('<q', int('srg00lgbif', 32))[:-1]
                   + struct.pack('<q', int('4c6u07sq', 32))[:-3],
                   }),
        ),
    ]

for gfpoly, fcr, prim in itertools.product(xrange(2**8), xrange(2**8), xrange(2**8)):
    for encoded_len, data_len, symbol_size, candidates, expecteds in guesses:
        try:
            codec = reedsolomon.Codec(encoded_len, data_len, symbol_size,
                                      gfpoly, fcr, prim)
        except MemoryError:
            continue
        for candidate in candidates:
            encoded = codec.encode(candidate)
            if encoded in expecteds:
                print "Found (%i, %i, %i) using %s, %s, gfpoly %i, fcr %i, prim %i" \
                      % (encoded_len, data_len, symbol_size, candidate, encoded, gfpoly, fcr, prim)
                      break