Example #1
0
def initPresets():
    """
    Loads initial presets
    """
    for i in range(64):
        util.setMask[i] = 1 << i
        bit = util.setMask[i]
        util.clearMask[i] = ~bit
        kingAttack = bit | util.right(bit) | util.left(bit)
        kingAttack |= util.up(kingAttack) | util.down(kingAttack)
        kingAttacks[i] = kingAttack & util.clearMask[i]

        l1 = util.left(bit)
        l2 = util.left(bit, 2)
        r1 = util.right(bit)
        r2 = util.right(bit, 2)

        h1 = l2 | r2
        h2 = l1 | r1

        knightAttacks[i] = util.up(h1) | util.down(h1) | util.up(
            h2, 2) | util.down(h2, 2)

        # pawn attacks
        wRightAttack = util.upRight(bit)
        wLeftAttack = util.upLeft(bit)
        bRightAttack = util.downRight(bit)
        bLeftAttack = util.downLeft(bit)
        pawnAttacks[0][i] = (wRightAttack | wLeftAttack)
        pawnAttacks[1][i] = (bRightAttack | bLeftAttack)

    generateOccupancyVariations(True)
    generateMoveDatabase(True)
    generateOccupancyVariations(False)
    generateMoveDatabase(False)
Example #2
0
def move_robot():
    global x_deviation, y_max, tolerance
    
    if(abs(x_deviation)<tolerance):
        if(y_max>0.9):
            ut.red_light("ON")
            ut.stop()
            print("reached person...........")
    
        else:
            ut.red_light("OFF")
            ut.forward()
            print("moving robot ...FORWARD....!!!!!!!!!!!!!!")
    
    
    else:
        ut.red_light("OFF")
        if(x_deviation>=tolerance):
            delay1=get_delay(x_deviation)
                
            ut.left()
            time.sleep(delay1)
            ut.stop()
            print("moving robot ...Left....<<<<<<<<<<")
    
                
        if(x_deviation<=-1*tolerance):
            delay1=get_delay(x_deviation)
                
            ut.right()
            time.sleep(delay1)
            ut.stop()
            print("moving robot ...Right....>>>>>>>>")
def initPresets():
    """
    Loads initial presets
    """
    for i in range(64):
        util.setMask[i] = 1 << i
        bit = util.setMask[i]
        util.clearMask[i] = ~bit
        kingAttack = bit | util.right(bit) | util.left(bit)
        kingAttack |= util.up(kingAttack) | util.down(kingAttack)
        kingAttacks[i] = kingAttack & util.clearMask[i]

        l1 = util.left(bit)
        l2 = util.left(bit, 2)
        r1 = util.right(bit)
        r2 = util.right(bit, 2)

        h1 = l2 | r2
        h2 = l1 | r1

        knightAttacks[i] = util.up(h1) | util.down(h1) | util.up(h2, 2) | util.down(h2, 2)

        # pawn attacks
        wRightAttack = util.upRight(bit)
        wLeftAttack = util.upLeft(bit)
        bRightAttack = util.downRight(bit)
        bLeftAttack = util.downLeft(bit)
        pawnAttacks[0][i] = (wRightAttack | wLeftAttack)
        pawnAttacks[1][i] = (bRightAttack | bLeftAttack)

    generateOccupancyVariations(True)
    generateMoveDatabase(True)
    generateOccupancyVariations(False)
    generateMoveDatabase(False)
def move_robot():
    global x_deviation, y_deviation, tolerance, arr_track_data
    
    print("moving robot .............!!!!!!!!!!!!!!")
    print(x_deviation, y_deviation, tolerance, arr_track_data)
    
    if(abs(x_deviation)<tolerance and abs(y_deviation)<tolerance):
        cmd="Stop"
        delay1=0
        ut.stop()
        ut.red_light("ON")
    
    else:
        ut.red_light("OFF")
        if (abs(x_deviation)>abs(y_deviation)):
            if(x_deviation>=tolerance):
                cmd="Move Left"
                delay1=get_delay(x_deviation,'l')
                
                ut.left()
                time.sleep(delay1)
                ut.stop()
                
            if(x_deviation<=-1*tolerance):
                cmd="Move Right"
                delay1=get_delay(x_deviation,'r')
                
                ut.right()
                time.sleep(delay1)
                ut.stop()
        else:
            
            if(y_deviation>=tolerance):
                cmd="Move Forward"
                delay1=get_delay(y_deviation,'f')
                
                ut.forward()
                time.sleep(delay1)
                ut.stop()
                
            if(y_deviation<=-1*tolerance):
                cmd="Move Backward"
                delay1=get_delay(y_deviation,'b')
                
                ut.back()
                time.sleep(delay1)
                ut.stop()
    
    
    arr_track_data[4]=cmd
    arr_track_data[5]=delay1
Example #5
0
    def encrypt(self, msg):
        msglen = len(msg)
        msgbytes = bytearray(msglen + 1 + BLOCK_SIZE - ((msglen + 1) % BLOCK_SIZE))
        msgbytes[:msglen] = msg

        # add null byte and random byte padding as necessary
        msgbytes[msglen] = NULL_BYTE
        for i in xrange(msglen + 1, len(msgbytes)):
            msgbytes[i] = random.randint(0, 255)

        output = bytearray(1)
        output[0] = GUARD_BYTE

        for i in xrange(0, len(msgbytes), BLOCK_SIZE):
            block = msgbytes[i:i+BLOCK_SIZE]

            leftblock = util.left(block)
            rightblock = util.right(block)

            leftmd = bytearray(hashlib.sha1(str(leftblock) + str(self.leftkey)).digest())
            rightcipher = bytearray(leftmd[i] ^ rightblock[i] for i in xrange(len(leftmd)))
            rightmd = bytearray(hashlib.sha1(str(rightcipher) + str(self.rightkey)).digest())
            leftcipher = bytearray(rightmd[i] ^ leftblock[i] for i in xrange(len(rightmd)))

            output.extend(leftcipher)
            output.extend(rightcipher) 

        return util.base32(int(util.bytestohex(output), 16)) + '\n'
Example #6
0
    def decrypt(self, cipher_line):
        if not util.is_encrypted(cipher_line):
            raise KarnError('"%s" is not encrypted!' % cipher_line)
            
        # convert from base 32 to bytes literal
        cipherbytes = bytearray.fromhex(unicode(util.inttohex(int(cipher_line.strip(), 32))))

        output = bytearray()
        # start at byte 1 because byte 0 is the guard byte
        for i in xrange(1, len(cipherbytes), BLOCK_SIZE):
            cipher = cipherbytes[i:i+BLOCK_SIZE]
            
            # + is the concatenation operator in python
            # ^ is the xor operator
            leftmd = bytearray(hashlib.sha1(str(util.right(cipher)) + str(self.rightkey)).digest())
            leftcipher = util.left(cipher)
            plaintext = bytearray(leftmd[i] ^ leftcipher[i] for i in xrange(len(leftmd)))
            rightmd = bytearray(hashlib.sha1(str(plaintext) + str(self.leftkey)).digest())
            rightcipher = util.right(cipher)
            plaintext.extend(bytearray(rightmd[i] ^ rightcipher[i] for i in xrange(len(rightmd))))

            # break if we decrypted a null byte
            output.extend(plaintext.partition('\x00')[0])
            if '\x00' in plaintext:
                break

        # we are expecting an ascii string, so print debug info 
        # if any decrypted character is out of ascii range
        if any(i > 127 for i in output):
            print 'couldn\'t decrypt ciphertext: %s' % cipher_line
            print 'with key: %d' % self.key
            print 'output: %s' % output
            raise DecryptionError(cipher_line, self.key, output)

        return str(output)
def move_robot():
    global x_deviation, y_max, tolerance, arr_track_data

    print("moving robot .............!!!!!!!!!!!!!!")
    print(x_deviation, tolerance, arr_track_data)

    y = 1 - y_max  #distance from bottom of the frame

    if (abs(x_deviation) < tolerance):
        delay1 = 0
        if (y < 0.1):
            cmd = "Stop"
            ut.red_light("ON")
            ut.stop()
        else:
            cmd = "forward"
            ut.red_light("OFF")
            ut.forward()

    else:
        ut.red_light("OFF")
        if (x_deviation >= tolerance):
            cmd = "Move Left"
            delay1 = get_delay(x_deviation)

            ut.left()
            time.sleep(delay1)
            ut.stop()

        if (x_deviation <= -1 * tolerance):
            cmd = "Move Right"
            delay1 = get_delay(x_deviation)

            ut.right()
            time.sleep(delay1)
            ut.stop()

    arr_track_data[4] = cmd
    arr_track_data[5] = delay1