Advertisement
ssccsscc

TPT - FILT ctype bruteforce

Jul 14th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <climits>
  2. #include <fstream>
  3.  
  4. struct Color {
  5.     int r;
  6.     int g;
  7.     int b;
  8.     unsigned int color;
  9. };
  10.  
  11. struct ArrayInfo {
  12.     Color **Array2;
  13.     int Length;
  14.     int LastIndex;
  15. };
  16.  
  17. Color* wavelengthToDecoColour(unsigned int wl) // function from TPT source code
  18. {
  19.     int x = 0;
  20.     int colg = 0;
  21.     int colb = 0;
  22.     int colr = 0;
  23.     for (x = 0; x<12; x++) {
  24.         colr += (wl >> (x + 18)) & 1;
  25.         colb += (wl >> x) & 1;
  26.     }
  27.     for (x = 0; x<12; x++)
  28.         colg += (wl >> (x + 9)) & 1;
  29.     x = 624 / (colr + colg + colb + 1);
  30.     if (0>0 && 0 <= 4)  //replaced element life with 0, because default FILT life is 0
  31.         int cola = 127 + 0 * 30;
  32.     else
  33.         int cola = 127;
  34.     colr *= x;
  35.     colg *= x;
  36.     colb *= x;
  37.     if (colr > 255) colr = 255;
  38.     else if (colr < 0) colr = 0;
  39.     if (colg > 255) colg = 255;
  40.     else if (colg < 0) colg = 0;
  41.     if (colb > 255) colb = 255;
  42.     else if (colb < 0) colb = 0;
  43.     return new Color{ colr,colg,colb,wl };
  44. }
  45.  
  46. bool IsColorExist(ArrayInfo* a, Color* c) {
  47.     for (size_t i = 0; i < a->LastIndex; i++)
  48.     {
  49.         if (a->Array2[i]->r == c->r) {
  50.             if (a->Array2[i]->g == c->g) {
  51.                 if (a->Array2[i]->b == c->b) {
  52.                     return true;
  53.                 }
  54.             }
  55.         }
  56.     }
  57.     return false;
  58. }
  59.  
  60. void InsertColor(ArrayInfo* a, Color* c) {
  61.     if (!IsColorExist(a, c)) {
  62.         a->Array2[a->LastIndex] = c;
  63.         a->LastIndex++;
  64.     }
  65.     else
  66.     {
  67.         delete c;
  68.     }
  69. }
  70.  
  71. int main()
  72. {
  73.     ArrayInfo* a = new ArrayInfo();
  74.     a->Length = 5000;   //How many colors to expect
  75.     a->LastIndex = 0;
  76.     a->Array2 = new Color*[a->Length];
  77.  
  78.     unsigned int i = 1;
  79.     while (a->LastIndex < a->Length - 1 && i < UINT_MAX) {
  80.         InsertColor(a, wavelengthToDecoColour(i));
  81.         i++;
  82.     }
  83.  
  84.     std::ofstream outfile;
  85.     outfile.open("output.txt", std::ios_base::app);
  86.  
  87.     for (size_t i = 0; i < a->LastIndex; i++)
  88.     {
  89.         outfile << a->Array2[i]->color << " " << a->Array2[i]->r << " " << a->Array2[i]->g << " " << a->Array2[i]->b << std::endl;
  90.     }
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement