Пример #1
0
def test_v2():
    for i in lrange(300) + [100000]:
        assert bitlen(1 << i) == i + 1
        assert bitlen((1 << i) - 1) == i
    for i in v2_testcases():
        assert v2(i) == v2_old(i), (hex(i), v2(i), v2_old(i))
        pass
Пример #2
0
    def compute(self, basis):
        """Calculate the permutation from a (transformed) basis.

        Here we calculate the singletons from the transformed basis.
        The same calculations with the standard basis self.basis yields 
        the singletons  0,...,23 in that order. So the singletons from 
        the transformed basis are the images of 0,...,23. 

        The tables self.basis_augment, self.col_aux_table, 
        self.bw_aux_table, self.out_table[i] are used.

        Singleton i is represented as 2**i, so at the end we have to take
        binary logarithms.
        """
        basis = basis[:12]
        for l in self.basis_augment:
            basis.append(reduce(__xor__, [basis[x] for x in l], 0))
        t = []
        for z in self.col_aux_table + self.bw_aux_table:
            t.append(reduce(__and__, [basis[i] ^ -s for (i, s) in z]))
        out = []
        st = len(self.col_aux_table)
        for i in range(24):
            m = t[st + (i >> 2)] & t[self.out_table[i]]
            out.append(v2(m))
        return out
Пример #3
0
 def display_operand(value):
     if value in registers:
         return 'o[%d]' % registers[value]
     if value == 0:
         return "0"
     if bitweight(value) == 1:
         return "i[%d]" % v2(value)
     raise ValueError("Illegal operand in straight line program")
Пример #4
0
def test_lsbit24(gc):
    for x in lsbit24_testcases():
        try:
            v_ref = min(v2(x), 24)
        except:
            v_ref = 24
        v = gc.lsbit24(x)
        assert v == v_ref, (hex(x), v, v_ref)
    print("test of lsbit determination passed")
Пример #5
0
 def operand_name(self, x, registers):
     if x in registers:
         return self.register_name(registers[x])
     if x == 0:
         return "0"
     r = v2(x)
     assert x == 1 << r
     return "(%s)(%s)" % (self.type_name,
                          self.array_entry(self.input_name, r))
Пример #6
0
def make_theta_table():
    r"""Creates the theta function for the Parker Loop
    theta() is a function from the Golay code C to the Golay cocode C*.

    Multiplication '(*)' in the Parker loop is defined by:

           a (*) b = (a ^ b) * (-1) ** scalar(theta(a),b) ,

    Where '^' is the vector addition in GF(2)**12, and  scalar(.,.)
    is the scalar product defined on C x C*.     

    More specifically, theta is a quadratic form from C onto C*. The 
    basis cc_i, i=0,...,11 of the cocode defined here is reciprocal to 
    the basis c_i, i=0,...,11 of the cocode defined here. 
    Define   theta(i)[j] = theta(i) * c_j.   Then 

            theta(i)  = sum[1 << theta(i)[j] for j in range(12) ]. 
 
    To define theta as a quadratic form, it suffices to define theta 
    on the basis vectors. We define theta on the basis vectors as
    given by function theta_to_basis_vector(v).

    There is a symmetric bilinear form B : from C x C onto C*
    associated with theta on all pairs of basis vectors satisfying:

             B(x,y) = theta(x+y) + theta(x) + theta(y)   .        
             B(x,y) = x :math:`\cap` Y

    Here :math:`\cap means intersection (i.e. bitwise 'and' in 
    GF(2)**24) of two Golay code words. This allows us to compute 
    theta(x), for all Golay code words, if theta is given on a 
    basis of the Golay code.
    """
    assert Mat24Tables.gcode_to_vect(0x800) == 0xffffff
    theta_table = numpy.zeros(0x800, dtype = uint16)

    thetas = theta_basis_vectors()
    for i in range(11):
         theta_table[1 << i] = Mat24Tables.vect_to_cocode(thetas[i])
 
    for i in range(0x800):
        if (i & (i-1)) != 0:    # i.e. if i is not 0 or a power of 2
            i0 = 1 << v2(i) 
            i1 = i ^ i0
            cap = Mat24Tables.gcode_to_vect(i0) 
            cap &= Mat24Tables.gcode_to_vect(i1)
            cc = Mat24Tables.vect_to_cocode(cap)
            theta_table[i] = theta_table[i0] ^ theta_table[i1] ^ cc
    return theta_table
Пример #7
0
def lsbit24(x):
    return v2(x | 0x1000000)
Пример #8
0
def lsbit24(x):
    """Return position of least significant bit of (x & 2**24)"""
    return v2(x | 0x1000000)