コード例 #1
0
 def generateKBkeys(self, keyBlockType):
     if keyBlockType == "A": 
         for i in self.KBPK:
             self.KBEK = self.KBEK + chr(ord(i) ^ ord("E"))
             self.KBMK = self.KBMK + chr(ord(i) ^ ord("M"))
     elif keyBlockType == "B":
         KBEK_1 = CMAC.generateMAC("\x01\x00\x00\x00\x00\x00\x00\x80",self.KBPK)
         KBEK_2 = CMAC.generateMAC("\x02\x00\x00\x00\x00\x00\x00\x80",self.KBPK)
         self.KBEK = "".join(KBEK_1 + KBEK_2)
         KBMK_1 = CMAC.generateMAC("\x01\x00\x01\x00\x00\x00\x00\x80",self.KBPK)
         KBMK_2 = CMAC.generateMAC("\x02\x00\x01\x00\x00\x00\x00\x80",self.KBPK)
         self.KBMK = "".join(KBMK_1 + KBMK_2)
コード例 #2
0
    def __init__(self, numFeatures, features, numActions, memorySize, epsilon,
                 numTilings, tableDimensionality, delta, alpha, gamma,
                 layerObj):

        self.layerObj = layerObj

        self.bellmanError = 0.0
        self.numFeatures = numFeatures
        self.numActions = numActions
        self.delta = delta
        self.gamma = gamma
        self.alpha = alpha
        self.epsilon = epsilon

        self.features = []
        for i in range(numFeatures):
            self.features.append(features[i])

        # initialize current and next state
        self.initializeState()

        # sanity check print function
        #self.printQLearningParams ()

        # initialize CMAC arrays
        self.cmac = CMAC.CMAC(alpha, numFeatures, 1, memorySize, gamma,
                              numTilings, tableDimensionality)
コード例 #3
0
 def __init__(self,KBPK='\x89\xE8\x8C\xF7\x93\x14\x44\xF3\x34\xBD\x75\x47\xFC\x3F\x38\x0C',key='\xF0\x39\x12\x1B\xEC\x83\xD2\x6B\x16\x9B\xDC\xD5\xB2\x2A\xAF\x8F'):
     self.tempKeyBlock = list()
     self.finalKeyBlock = list()
     self.KBPK = KBPK
     self.key = key
     print self.KBPK
     print self.key 
     self.keyBlockType = self.getKeyBlockType()
     self.generateKBkeys(self.keyBlockType)
     print self.KBEK.encode("hex")
     print self.KBMK.encode("hex")
     self.header = self.createHeader()
     self.randomPadding = self.getRandomPadding() 
     self.ptKeyBlock = self.generatePtKB()
     print self.ptKeyBlock.encode("hex") 
     if (self.keyBlockType == "A"):  
         self.keyIV = "".join(self.header)[0:8]
         self.encryptedKey = self.encryptKey(self.ptKeyBlock)
         self.tempKeyBlock.append(self.header)
         self.tempKeyBlock.append(self.encryptedKey)
         self.MAC = self.getMAC("".join(self.tempKeyBlock))
         self.finalKeyBlock.append(self.header)
         self.finalKeyBlock.append(self.encryptedKey.encode("hex"))    
         self.finalKeyBlock.append(self.MAC.encode("hex").upper)
         
     elif (self.keyBlockType == "B"):
         self.tempKeyBlock.append(self.header)
         self.tempKeyBlock.append(self.ptKeyBlock)
         print self.tempKeyBlock 
         self.MAC = CMAC.generateMAC("".join(self.tempKeyBlock),self.KBMK)
         self.keyIV = self.MAC
         self.encryptedKey = self.encryptKey(self.ptKeyBlock)
         self.finalKeyBlock.append(self.header)
         self.finalKeyBlock.append(self.encryptedKey.encode("hex"))    
         self.finalKeyBlock.append(self.MAC.encode("hex").upper())