def test_bittest_neg(self):
        # Not meant to be called with other values than int or long
        self.failUnlessRaises(TypeError, ar._bittest, 0.0, 1)
        self.failUnlessRaises(TypeError, ar._bittest, 0b101, 1.0)

        # overflow of offset
        self.failUnlessEqual(ar._bittest(0b00000,2),0)
        self.failUnlessEqual(ar._bittest(0b0,2),0)
        self.failUnlessEqual(ar._bittest(0b0,283),0)
        self.failUnlessEqual(ar._bittest(0b1,3),0)
        self.failUnlessEqual(ar._bittest(0b10000,8),0)

        # negativ offset
        self.failUnlessEqual(ar._bittest(0b101,-1),0)
        self.failUnlessEqual(ar._bittest(0b101,-2),1)
        self.failUnlessEqual(ar._bittest(0b101,-0),1)

        # negativ value
        self.failUnlessEqual(ar._bittest(-0b1111,2),1)
        self.failUnlessEqual(ar._bittest(-0b1011,2),0)
Example #2
0
    def test_bittest_neg(self):
        # Not meant to be called with other values than int or long
        self.failUnlessRaises(TypeError, ar._bittest, 0.0, 1)
        self.failUnlessRaises(TypeError, ar._bittest, 0b101, 1.0)

        # overflow of offset
        self.failUnlessEqual(ar._bittest(0b00000, 2), 0)
        self.failUnlessEqual(ar._bittest(0b0, 2), 0)
        self.failUnlessEqual(ar._bittest(0b0, 283), 0)
        self.failUnlessEqual(ar._bittest(0b1, 3), 0)
        self.failUnlessEqual(ar._bittest(0b10000, 8), 0)

        # negativ offset
        self.failUnlessEqual(ar._bittest(0b101, -1), 0)
        self.failUnlessEqual(ar._bittest(0b101, -2), 1)
        self.failUnlessEqual(ar._bittest(0b101, -0), 1)

        # negativ value
        self.failUnlessEqual(ar._bittest(-0b1111, 2), 1)
        self.failUnlessEqual(ar._bittest(-0b1011, 2), 0)
Example #3
0
    def affine_point_mul(self, k, x, y):
        Q = (0,0) # point at infinity
        first = True 

        for i in range(0,k.bit_length()):
            Q = ar.ecgf2m_dbl_point(Q[0],Q[1],self._fx,self._a)

            if (ar._bittest(k,(k.bit_length()-1) - i) == 0b1):
                if (first):
                    Q = (x,y)
                    first = False                    
                else:
                    Q = ar.ecgf2m_add_point(Q[0],Q[1],x,y,self._fx,self._a)
            #print "DBG:\ni=%d\nQ[0]=%s\nQ[1]=%s\n" % (i,hex(Q[0]),hex(Q[1]))
        return Q
Example #4
0
    def test_bittest_pos(self):
        self.failUnlessEqual(ar._bittest(0b1, 0), 1)
        self.failUnlessEqual(ar._bittest(0b0, 0), 0)
        self.failUnlessEqual(ar._bittest(0b111, 1), 1)
        self.failUnlessEqual(ar._bittest(0b101, 1), 0)

        self.failUnlessEqual(ar._bittest(0b1000, 3), 1)
        self.failUnlessEqual(ar._bittest(0b1000, 2), 0)
        self.failUnlessEqual(ar._bittest(8, 3), 1)
        self.failUnlessEqual(ar._bittest(8, 2), 0)
        self.failUnlessEqual(ar._bittest(8L, 3), 1)
        self.failUnlessEqual(ar._bittest(8L, 2), 0)

        self.failUnlessEqual(
            ar._bittest(
                0b10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000010100001,
                283), 1)
        self.failUnlessEqual(
            ar._bittest(
                15541351137805832567355695254588151253139254712417116170014499277911234281641667989665L,
                283), 1)
Example #5
0
    def affine_point_mul(self, k, x, y):
        Q = (0, 0)  # point at infinity
        first = True

        for i in range(0, k.bit_length()):
            Q = ar.ecgf2m_dbl_point(Q[0], Q[1], self._fx, self._a)

            if (ar._bittest(k, (k.bit_length() - 1) - i) == 0b1):
                if (first):
                    Q = (x, y)
                    first = False
                else:
                    Q = ar.ecgf2m_add_point(Q[0], Q[1], x, y, self._fx,
                                            self._a)
            #print "DBG:\ni=%d\nQ[0]=%s\nQ[1]=%s\n" % (i,hex(Q[0]),hex(Q[1]))
        return Q
    def test_bittest_pos(self):
        self.failUnlessEqual(ar._bittest(0b1,0),1)
        self.failUnlessEqual(ar._bittest(0b0,0),0)
        self.failUnlessEqual(ar._bittest(0b111,1),1)
        self.failUnlessEqual(ar._bittest(0b101,1),0)

        self.failUnlessEqual(ar._bittest(0b1000,3),1)
        self.failUnlessEqual(ar._bittest(0b1000,2),0)
        self.failUnlessEqual(ar._bittest(8,3),1)
        self.failUnlessEqual(ar._bittest(8,2),0)
        self.failUnlessEqual(ar._bittest(8L,3),1)
        self.failUnlessEqual(ar._bittest(8L,2),0)
        
        self.failUnlessEqual(ar._bittest(0b10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000010100001,283),1)
        self.failUnlessEqual(ar._bittest(15541351137805832567355695254588151253139254712417116170014499277911234281641667989665L,283),1)