def fitness_function(password):
    # defins with only one argument so that it can be used within other max() and map function
    # even though blurry_memory can take multiple passwords at once, sometimes it doesn't return the same number of passwords
    # because of this I made it so that it only takes one password and returns a float value as its fitness since this it how the
    # fitness function is used in the rest of the program
    fitness = list(blurry_memory([password], 170219976, 0).values())
    return fitness[0]
Ejemplo n.º 2
0
 def get_fitness(self, population):
     """
     Calls the executable to compute fitness of each individuals of population
     :param population: Population for which fitness must be computed
     :type population: List of individuals (so string)
     :return: Dictionary with individuals as keys and values are fitness
     :rtype: Dictionary
     """
     return blurry_memory(population, self.student_number, self.password_index)
def compute_fitness(pop, password_type):
    """
    this method computes the fitness for the population
    :param pop: population - a list of Chromosomes
    :param password_type: (0 or 1) - the password for which to compute the fitness of the population for.
    :return: poplutaion - a list of Chromosomes with their evaluated fitness value
    """
    population_list = [individual.sequence for individual in pop]
    evaluated_pop = blurry_memory(population_list, STUDENT_NO, password_type)
    pop = [Chromosome(key, value) for key, value in evaluated_pop.items()]
    return pop
Ejemplo n.º 4
0
    def crack(self, argv, showPlt=True):
        # init population
        population = []
        for i in range(self.p_sz):
            population.append(util.random_pass(self.pass_len))
        residue = population
        # maxIter = 5000
        curIter = 0
        t0 = time.time()

        # plot data
        stats = []
        while True:
            # filling the population to its original size
            # in case duplication happen
            # while len(population) < self.p_sz:
            #     population.append(util.random_pass(self.pass_len))
            heuristics = blurry_memory(population, self.stuId, int(argv))
            # pdb.set_trace()
            best = util.best_item_by_value(heuristics)
            stats.append(best[1])
            if best[1] == 1.0:
                # result
                break
            # selection (parents for evolving)
            parents, residue = self.selection(heuristics)
            # crossover & mutation (evolve)
            offsprings = self.evolve(parents)
            # pdb.set_trace()
            population = offsprings  #+ residue
            # print(len(population))
            curIter += 1

        finish = time.time() - t0
        print("Cracked in {} iteration, and {} seconds! \nIt is = {}".format(
            curIter, finish, best[0]))

        # # plot all iterations
        if showPlt:
            fig, ax = plt.subplots()
            plt.plot(stats)
            fig.suptitle('Total time used: {}'.format(finish), fontsize=14)
            ax.set_xlabel('Generation')
            ax.set_ylabel('Fitness Score')
            plt.show()

            # save plot
            fig.savefig('../plot/amnesiac{}.png'.format(p_idx))

        return curIter, finish
Ejemplo n.º 5
0
def get_fitness_of_second_password(guess):
    fitness_ = blurry_memory(["__________", guess], 190189237, 1)
    return fitness_[guess]
Ejemplo n.º 6
0
def get_fitness_of_first_password(guess):
    fitness_ = blurry_memory([guess, "__________"], 190189237, 0)
    return fitness_[guess]