Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <math.h>
  5. #include "code.h"
  6.  
  7. Bitkey generate_keys(){
  8. Bitkey tab;
  9. int i = 0;
  10. for(i = 0; i < NB_OCT; i++)
  11. tab.values[i] = rand()%256;
  12. return tab;
  13. }
  14.  
  15.  
  16.  
  17.  
  18. void tri_a_bulle(Bitkey *tab){
  19.  
  20. Bitkey* tmp = tab;
  21. Bitkey tmp1;
  22. int cmp = 1;
  23. int i = 0;
  24. int j;
  25. float tmp2;
  26. float tab2[8];
  27. for(j = 0;j<NB_OCT;j++)
  28. tab2[j] = fitness_key(&tab[j]);
  29. while(cmp != 0){
  30. cmp = 0;
  31. i=0;
  32. while( i < NB_OCT - 1){
  33. if(tab2[i] < tab2[i+1]){
  34. tmp1 = tmp[i];
  35. tmp[i] = tmp[i+1];
  36. tmp[i+1] = tmp1;
  37. tmp2 = tab2[i];
  38. tab2[i] = tab2[i+1];
  39. tab2[i+1] = tmp2;
  40. cmp ++;
  41. }
  42. i++;
  43. }
  44. }
  45. }
  46.  
  47.  
  48. Bitkey acouplement(Bitkey*tab){
  49. int i,j;
  50. Bitkey tab1;
  51. for(i = 0; i< NB_OCT;i++)
  52. tab1.values[i] = 0;
  53. for(i = 0; i < 8; i++)
  54. for(j = 0;j<8; j++){
  55. int d = 0;
  56. if((tab[0].values[i] & (1 << j)) != 0)
  57. d++;
  58. if((tab[1].values[i] & (1 << j)) != 0)
  59. d++;
  60. if((tab[2].values[i] & (1 << j)) != 0)
  61. d++;
  62. if(d == 3 || d == 2){
  63. tab1.values[i] = tab1.values[i] | (1 << j);
  64. }
  65. }
  66. return tab1;
  67. }
  68.  
  69. Bitkey generate_cle_generation(int d){
  70. if(d == 0){
  71. return generate_keys();
  72. }
  73. int i = 0;
  74. Bitkey* tab = (Bitkey*)malloc(8*sizeof(Bitkey));
  75. for(i = 0;i < NB_OCT;i++){
  76. tab[i] = generate_cle_generation(d-1);
  77. }
  78. tri_a_bulle(tab);
  79. return acouplement(tab);
  80. }
  81.  
  82.  
  83.  
  84. int main(int argc, char const *argv[]) {
  85. srand(time(NULL));
  86. Bitkey cle = generate_cle_generation(7);
  87. enter_the_matrix(&cle);
  88.  
  89. return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement