Beispiel #1
0
 def show_batch_results(self, ideal_result, real_result):
   if ideal_result == real_result:
     Logger.success("{}/{} - 100%".format(ideal_result, real_result), True)
   elif ideal_result == 0:
     Logger.error("0/{} - 0%".format(real_result), True)
   else:
     Logger.warning("{}/{} - {}%".format(ideal_result, real_result, round(100.0 * ideal_result / real_result, 2)), True)
Beispiel #2
0
    def crack(self):
        Logger.info("\nTrain on " + self._captcha)

        options = self.options

        if not options.mod:
            Logger.error("Can't crack without a mod")
            return None

        supposed_words = []

        processed = self.getImage()
        processed = self.cleanImage(processed)
        # Ensure that image is in black and white
        processed = self.blackAndWhite(processed)

        # List of images
        characters = self.getCharacters(processed)
        trained_chars = self.loadTrainedChars()

        Logger.subheader("Detected characters")

        # Go through each character
        for character in characters:
            # Transform image to list of lists
            a_char = self.imageTo2DBinaryList(character)

            similarity_best = 0.0
            similarity_letter = None

            for char, chars_list in trained_chars.iteritems():
                for a_trained_char in chars_list:
                    similarity = self.computeSimilarity(a_char, a_trained_char)

                    if similarity > similarity_best:
                        similarity_best = similarity
                        similarity_letter = char

            supposed_words.append((similarity_best, similarity_letter))

            Logger.log("{} {}%".format(similarity_letter, round(similarity_best, 2)))

        guess = ""
        multiple_probability = 1.0
        average_probability = 0.0
        all_guesed = True
        for probability, letter in supposed_words:
            if letter:
                guess += str(letter)
            else:
                guess += "_"
                all_guesed = False

            multiple_probability *= probability / 100
            average_probability += probability

        if len(guess):
            average_probability /= len(guess)

        Logger.subheader("Results")

        if all_guesed:
            Logger.success(guess)
        else:
            Logger.info("characters marked with _ are the ones that are not guessed:")
            Logger.error(guess)

        Logger.info("{}% Overall probability".format(round(multiple_probability * 100, 2)))
        Logger.info("{}% Average probability".format(round(average_probability, 2)))

        if not options.verbose:
            Logger.log(guess, True)
        return guess