Exemplo n.º 1
0
def gen_m_sequence(taps, init=0x2):
    degree = utils.get_highest_set_bit(taps)
    mask = (2 ** (1+degree)) - 1
    bins = init
    done = 0
    output = []
    while not done:
        output.append(1 if bins & 1 else 0)
        bins = ((bins >> 1) +
                ((utils.count_bits(taps & bins) % 2) << (degree-1))) & mask
        if bins == init or bins == 0:
            done = 1
    return numpy.array(output)
Exemplo n.º 2
0
def berlekamp_factorisation_check(a):
    # Check for two or more irreducable factors
    # from http://www.diva-portal.org/smash/get/diva2:414578/FULLTEXT01.pdf
    # gcd(f(x), f'(x))
    # (a >> 1) & 0x77777777 is a quick way of differentiating a gf2 poly < 32 bits
    if utils.gf2_gcd(a, (a >> 1) & 0x77777777) != 1:
        return False

    degree = utils.get_highest_set_bit(a)
    polys = [utils.gf2_mod(1 << (2*i), a) ^ (1 << i) for i in xrange(degree)]

    for i, div in enumerate(polys[:i]):
        for j in range(len(polys[i+1:])):
            polys[j+i+1] ^= div
            if polys[j+i+1] == 0:
                # Matrix of polys is not full rank
                return False

    return True