In another folder, there’s a treasure map, containing lots of “ARR!” and a lot of rubbish. R-Boy wonders if the number of occurrences of the string in the 8 directions can unlock a hidden message… Look at the map and help R-Boy find the hidden word. Note: to complete the flag, insert the found message between “{FLG:” and “}” without any blank spaces after the “:” or before the “}”.”

The challenge provide us a .txt file with 30000 strings (each of them of length 30000).

As written in the text, we have simply to count the number of occurences of the string “ARR!” in the file. We can count them with a simple program that, for each starting point, looks in all the 8 directions.

So the total number of occurences is 47723067.

We lost some time trying to figure out how to use that number to find the “hidden message”. In the end, after many attemps, we simply converted the number from hex (47723067) to ascii (Gr0g).

ARR! The pirates love the grog!

Then finally the searched flag is: {FLG:Gr0g}

Source code:

#include <bits/stdc++.h>

using namespace std;

int main()
{
  vector<string> lines;
  string arr = "ARR!";

  ifstream file;
  string line;
  file.open("island.txt");
  while (getline(file, line)) lines.push_back(string(line));

  long long cont = 0;

  for (auto i = 0; i < lines.size(); i++)
  {
    int s = lines[i].size();

    for (auto j = 0; j < s; j++)
    {
      if (lines[i][j] != 'A') continue;

      for(int x = -1; x < 2; x++)
      for(int y = -1; y < 2; y++)
      {
        bool f=true;
        for(int z=0; z<4; z++)
        {
          if(i+z*x < 0) f = false;
          else if(i+z*x >= s) f = false;
          else if(j+z*y < 0) f = false;
          else if(j+z*y >= s) f = false;
          else f = f && ( lines[i+z*x][j+z*y] == arr[z] );
        }
        cont += f;
      }
    }
  }

  cout << cont << endl;

  return 0;
}