Thursday, March 25, 2021

Eden Cluster - Obfuscated C++ Code

 

                        #include <iostream>  
                     #include <vector> // model
                   #include <Windows.h> // Edena
                   using namespace std; const int L
                = 180; int klaster[L][L]; int done = 0;
             void Init(){for(int i = 0; i < L; i++) for(
            int j = 0; j < L; j++) klaster[i][j] = 0; klaster
         [L /2][L/2]=1;}void Rysuj(){ cout<<"\x1b[2J"; for(int
         i = 0; i < L; i++) for ( int j=0; j < L; j++) { if (
        klaster[i] [j]) { cout<< "\x1b[" << j << ";" << i*2<<"H";
       cout<<"\x1b[47m  \x1b[0m\x1b["<<L<<";"<<L<<"H";}}cout<<
        endl;} class para{public: para(int _i, int _j):i(_i),
        j(_j) {} int i; int j; };  void  EdenA() { vector<para>
           brzeg; brzeg.clear(); for (int i = 1; i < L - 1; i++)
          for (int j = 1; j < L - 1; j++) { if (klaster[i][j] ==
           0 && (klaster[i + 1][j] ||klaster[i - 1][j]||klaster
           [i][j - 1] || klaster[i][j + 1])) { if (i == 1 || j
          == 1 || i == L - 1 || j == L - 1) done = 1; brzeg.
          push_back(para(i, j)); } } if (brzeg.size() != 0)
           { // wybieramy losowo komórkę z brzegu // ***
           int k = int(floor(brzeg.size() * (rand()/float
             (RAND_MAX)))); klaster[brzeg[k].i][brzeg[k].
               j] = 1; } } int main() { srand(1001);
                 Init();//warunek poczatkowy i zarodek
                    for (; done == 0;) // pętla
                     { EdenA(); // krok modelu A
                         } Rysuj(); //rysuj
                           }   //stan


Live code of this (lecture)

Eden model (wikipedia)



No comments:

Post a Comment

Soda Constructor (Revisited)