예제 #1
0
    def learn(self, val, indice, isForced, dictionary):

        if self.strVal is None or isForced:
            tmp = val[indice:]
            self.log.debug("Taille MD5 " + str(len(tmp)))
            # MD5 size = 16 bytes = 16*8 = 128
            if (len(tmp) >= 128):
                binVal = tmp[0:128]
                # We verify its realy the MD5
                var = dictionary.getVariableByID(self.id_var)
                (binToHash, strToHash) = var.getValue(False, dictionary)

                toHash = TypeConvertor.bin2string(binToHash)
                self.log.debug("Will hash the followings : " + toHash)

                md5core = hashlib.md5(self.init)
                md5core.update(toHash)

                md5Hex = md5core.digest()

                self.log.debug("We should received an MD5 = " +
                               str(TypeConvertor.hex2bin(md5Hex)))
                self.log.debug("We have received " + str(binVal))

                if (TypeConvertor.hex2bin(md5Hex) == binVal):
                    self.binVal = TypeConvertor.hex2bin(md5Hex)
                    self.strVal = TypeConvertor.bin2strhex(self.binVal)
                    self.log.debug("Perfect, there are equals we return  " +
                                   str(len(binVal)))
                    return indice + len(binVal)
                else:
                    return -1

            else:
                return -1

        self.log.debug("value = " + str(self.strVal) + ", isForced = " +
                       str(isForced))
        return -1
예제 #2
0
    def learn(self, val, indice, isForced, dictionary):

        if self.strVal is None or isForced:
            tmp = val[indice:]
            self.log.debug("Taille MD5 " + str(len(tmp)))
            # MD5 size = 16 bytes = 16*8 = 128
            if (len(tmp) >= 128):
                binVal = tmp[0:128]
                # We verify its realy the MD5
                var = dictionary.getVariableByID(self.id_var)
                (binToHash, strToHash) = var.getValue(False, dictionary)

                toHash = TypeConvertor.bin2string(binToHash)
                self.log.debug("Will hash the followings : " + toHash)

                md5core = hashlib.md5(self.init)
                md5core.update(toHash)

                md5Hex = md5core.digest()

                self.log.debug("We should received an MD5 = " + str(TypeConvertor.hex2bin(md5Hex)))
                self.log.debug("We have received " + str(binVal))

                if (TypeConvertor.hex2bin(md5Hex) == binVal):
                    self.binVal = TypeConvertor.hex2bin(md5Hex)
                    self.strVal = TypeConvertor.bin2strhex(self.binVal)
                    self.log.debug("Perfect, there are equals we return  " + str(len(binVal)))
                    return indice + len(binVal)
                else:
                    return -1

            else:
                return -1

        self.log.debug("value = " + str(self.strVal) + ", isForced = " + str(isForced))
        return -1
예제 #3
0
    def generateValue(self, negative, dictionary):
        # Retrieve the value of the data to hash
        var = dictionary.getVariableByID(self.id_var)
        (binToHash, strToHash) = var.getValue(negative, dictionary)

        toHash = TypeConvertor.bin2string(binToHash)
        self.log.debug("Will hash the followings : " + toHash)

        md5core = hashlib.md5(self.init)
        md5core.update(toHash)

        md5Hex = md5core.digest()
        self.binVal = TypeConvertor.hex2bin(md5Hex)
        self.strVal = TypeConvertor.bin2strhex(self.binVal)
        self.log.debug("Generated MD5 = " + self.strVal)
예제 #4
0
    def generateValue(self, negative, dictionary):
        # Retrieve the value of the data to hash
        var = dictionary.getVariableByID(self.id_var)
        (binToHash, strToHash) = var.getValue(negative, dictionary)

        toHash = TypeConvertor.bin2string(binToHash)
        self.log.debug("Will hash the followings : " + toHash)

        md5core = hashlib.md5(self.init)
        md5core.update(toHash)

        md5Hex = md5core.digest()
        self.binVal = TypeConvertor.hex2bin(md5Hex)
        self.strVal = TypeConvertor.bin2strhex(self.binVal)
        self.log.debug("Generated MD5 = " + self.strVal)