Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- #include "code.h"
- Bitkey generate_keys(){
- Bitkey tab;
- int i = 0;
- for(i = 0; i < NB_OCT; i++)
- tab.values[i] = rand()%256;
- return tab;
- }
- void tri_a_bulle(Bitkey *tab){
- Bitkey* tmp = tab;
- Bitkey tmp1;
- int cmp = 1;
- int i = 0;
- int j;
- float tmp2;
- float tab2[8];
- for(j = 0;j<NB_OCT;j++)
- tab2[j] = fitness_key(&tab[j]);
- while(cmp != 0){
- cmp = 0;
- i=0;
- while( i < NB_OCT - 1){
- if(tab2[i] < tab2[i+1]){
- tmp1 = tmp[i];
- tmp[i] = tmp[i+1];
- tmp[i+1] = tmp1;
- tmp2 = tab2[i];
- tab2[i] = tab2[i+1];
- tab2[i+1] = tmp2;
- cmp ++;
- }
- i++;
- }
- }
- }
- Bitkey acouplement(Bitkey*tab){
- int i,j;
- Bitkey tab1;
- for(i = 0; i< NB_OCT;i++)
- tab1.values[i] = 0;
- for(i = 0; i < 8; i++)
- for(j = 0;j<8; j++){
- int d = 0;
- if((tab[0].values[i] & (1 << j)) != 0)
- d++;
- if((tab[1].values[i] & (1 << j)) != 0)
- d++;
- if((tab[2].values[i] & (1 << j)) != 0)
- d++;
- if(d == 3 || d == 2){
- tab1.values[i] = tab1.values[i] | (1 << j);
- }
- }
- return tab1;
- }
- Bitkey generate_cle_generation(int d){
- if(d == 0){
- return generate_keys();
- }
- int i = 0;
- Bitkey* tab = (Bitkey*)malloc(8*sizeof(Bitkey));
- for(i = 0;i < NB_OCT;i++){
- tab[i] = generate_cle_generation(d-1);
- }
- tri_a_bulle(tab);
- return acouplement(tab);
- }
- int main(int argc, char const *argv[]) {
- srand(time(NULL));
- Bitkey cle = generate_cle_generation(7);
- enter_the_matrix(&cle);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement