Fifteen Puzzle

Текст задания:

You are given 128 puzzles (https://en.wikipedia.org/wiki/15_puzzle)
The ith puzzle determines the ith bit of the flag:
* 1 if the puzzle is soluble
* 0 if the puzzle is unsoluble
Implement is_soluble() below, and use the code to get the flag!

Note: There is an important note on the News page about this challenge.

def is_soluble(i):
return 0
flag = ‘ ‘
for i in range(128):
flag = (‘1’ if is_soluble(i) else ‘0’) + flag
print(‘SharifCTF{%016x}’ % int(flag, 2))

puzzles.txt [18 КБ]

Итак, файл с обычными пятнашками, их 128 штук, нужно определить, можно ли решить каждую из них.
Внимание, такой способ решения крайне не рекомендован и подходит только самым скилловым говнокодерам!
Гуглим как определить, решаемы ли пятнашки, находим такую статью. Что ж, почти идеально. Открываем старый добрый Notepad++, и приводим наш файл к нужному виду. После всех необходимых замен получаем это:

new_puzzles.txt [11,7 КБ]

Дальше еще ужаснее, особо впечатлительным лучше не смотреть. Открываем python и генерируем 128 вызовов функции isSolvable(puzzle) c нужными параметрами:

for i in range(128):
    print 'isSolvable(puzzle'+str(i)+')? flag = "1" + flag : flag = "0" + flag;'

Открываем какой-нибудь С++ онлайн компилятор (например этот) и соединяем все вместе — код из статьи + 128 пазлов + 128 вызовов функции:

#include 
#include 
#define N 4
using namespace std;
 
int getInvCount(int arr[])
{
    int inv_count = 0;
    for (int i = 0; i < N * N - 1; i++)
    {
        for (int j = i + 1; j < N * N; j++)
        {
            if (arr[j] && arr[i] && arr[i] > arr[j])
                inv_count++;
        }
    }
    return inv_count;
}
 
int findXPosition(int puzzle[N][N])
{
    for (int i = N - 1; i >= 0; i--)
        for (int j = N - 1; j >= 0; j--)
            if (puzzle[i][j] == 0)
                return N - i;
}
 
bool isSolvable(int puzzle[N][N])
{
    int invCount = getInvCount((int*)puzzle);
 
    if (N & 1)
        return !(invCount & 1);
 
    else    
    {
        int pos = findXPosition(puzzle);
        if (pos & 1)
            return !(invCount & 1);
        else
            return invCount & 1;
    }
}
 
int main()
{
    std::string flag = "";
    
    int puzzle0[N][N] =
    {
        { 6, 8, 1, 5},
        { 4,15,12,14},
        { 7, 2,11,10},
        {0, 9,13, 3},
    };
    
    int puzzle1[N][N] =
    {
        {0, 3,10, 1},
        {14, 2, 6,11},
        {15, 8, 4, 7},
        { 5,13, 9,12},
    };
    
    int puzzle2[N][N] =
    {
        { 8,14,12, 2},
        {13, 4,0, 5},
        {15,11, 3, 9},
        { 7, 1,10, 6},
    };
    
    int puzzle3[N][N] =
    {
        {10,13, 6, 9},
        { 3, 8,15,14},
        {11,0, 7, 1},
        {12, 2, 4, 5},
    };
    
    int puzzle4[N][N] =
    {
        {10, 3,14,11},
        { 4, 7, 9,0},
        {12, 6, 8, 5},
        { 2,15,13, 1},
    };
    
    int puzzle5[N][N] =
    {
        {14,11, 8, 9},
        { 3, 6, 2, 4},
        {15, 1,12,0},
        {13, 5,10, 7},
    };
    
    int puzzle6[N][N] =
    {
        {12, 2, 8, 9},
        {13, 7, 6,15},
        { 1, 3,10,0},
        {14, 5,11, 4},
    };
    
    int puzzle7[N][N] =
    {
        {15,10, 7,12},
        {0, 8,14, 3},
        { 2,11, 4, 9},
        { 5, 1,13, 6},
    };
    
    int puzzle8[N][N] =
    {
        { 4,14, 1, 6},
        {0,10, 7, 9},
        { 3, 8, 2,11},
        {13,12,15, 5},
    };
    
    int puzzle9[N][N] =
    {
        {14,15, 1,11},
        {12, 6, 3, 4},
        { 9,10, 7, 8},
        {0, 5, 2,13},
    };
    
    int puzzle10[N][N] =
    {
        { 2,0, 4, 1},
        {10,13, 7,12},
        {14,15, 3, 9},
        { 8,11, 6, 5},
    };
    
    int puzzle11[N][N] =
    {
        { 5, 6, 8,15},
        {11, 2,13, 9},
        {14, 1,12, 3},
        { 4,10, 7,0},
    };
    
    int puzzle12[N][N] =
    {
        { 7,14, 4, 1},
        {10, 8, 9,13},
        {11, 2, 3, 5},
        {12,0,15, 6},
    };
    
    int puzzle13[N][N] =
    {
        { 1,12, 6, 7},
        {14,13, 3,0},
        { 5, 2, 8,10},
        { 4, 9,11,15},
    };
    
    int puzzle14[N][N] =
    {
        {14,0, 4,12},
        {11, 8, 9, 3},
        { 7, 1, 5,15},
        { 6, 2,10,13},
    };
    
    int puzzle15[N][N] =
    {
        {15,14,0, 4},
        { 2, 9, 1, 6},
        {12, 3,10, 5},
        { 7,13, 8,11},
    };
    
    int puzzle16[N][N] =
    {
        { 6, 7,13, 2},
        { 5,11, 4,12},
        { 8,14,0,15},
        { 1, 9,10, 3},
    };
    
    int puzzle17[N][N] =
    {
        {13, 7,15,10},
        { 9,11, 5, 4},
        {0,14, 6,12},
        { 2, 3, 1, 8},
    };
    
    int puzzle18[N][N] =
    {
        { 1, 6,13,11},
        { 5, 8,15,14},
        {12, 7, 3,10},
        { 9, 4,0, 2},
    };
    
    int puzzle19[N][N] =
    {
        { 4, 3,15,13},
        { 9,0,11, 5},
        { 8, 1, 7,12},
        {10, 2,14, 6},
    };
    
    int puzzle20[N][N] =
    {
        { 2, 7, 1, 8},
        { 5, 6, 3, 4},
        {10,14,13,11},
        {12, 9,15,0},
    };
    
    int puzzle21[N][N] =
    {
        { 8,12, 6,13},
        {11, 5,15,0},
        { 3, 1,14,10},
        { 9, 2, 7, 4},
    };
    
    int puzzle22[N][N] =
    {
        { 3,13,0, 9},
        { 1, 6, 5,11},
        {12, 7, 4,15},
        {14,10, 2, 8},
    };
    
    int puzzle23[N][N] =
    {
        {12, 5,14,0},
        { 9, 7, 6,11},
        {15, 4, 8, 3},
        {10, 1,13, 2},
    };
    
    int puzzle24[N][N] =
    {
        { 3, 5, 7, 6},
        {12, 9, 1,10},
        {13, 2,11,0},
        {15,14, 8, 4},
    };
    
    int puzzle25[N][N] =
    {
        { 2, 8, 9,13},
        {0,11,10, 4},
        {12, 7, 5, 6},
        { 3,14, 1,15},
    };
    
    int puzzle26[N][N] =
    {
        {0, 6, 5,10},
        {15,14,12,11},
        { 8, 3, 4, 7},
        { 9, 1,13, 2},
    };
    
    int puzzle27[N][N] =
    {
        {13, 8,14, 9},
        { 4,15, 1, 6},
        { 2, 7,12,0},
        {11, 3, 5,10},
    };
    
    int puzzle28[N][N] =
    {
        {13, 5,15, 4},
        { 2, 8,14, 7},
        {11,12, 6,0},
        { 3, 9,10, 1},
    };
    
    int puzzle29[N][N] =
    {
        { 8, 1, 5, 3},
        { 7, 9,11,15},
        { 4,10,13, 2},
        {0,12,14, 6},
    };
    
    int puzzle30[N][N] =
    {
        { 2, 1,0,10},
        { 4, 9, 6, 8},
        {11,14,15, 3},
        { 7,13, 5,12},
    };
    
    int puzzle31[N][N] =
    {
        { 3, 4, 7,10},
        {15, 1,0,11},
        {12, 5,14,13},
        { 9, 6, 2, 8},
    };
    
    int puzzle32[N][N] =
    {
        { 2, 8,15, 9},
        {13,14,11, 1},
        { 3, 7,0, 6},
        {12,10, 5, 4},
    };
    
    int puzzle33[N][N] =
    {
        {13,15, 9,0},
        {14, 2, 1, 4},
        {11, 3, 8, 7},
        {12,10, 6, 5},
    };
    
    int puzzle34[N][N] =
    {
        { 8, 2,10, 7},
        {11, 6,12,15},
        { 3, 4, 9,13},
        { 5,0,14, 1},
    };
    
    int puzzle35[N][N] =
    {
        {13,12, 6,15},
        {10, 1, 7, 5},
        { 2,0, 8, 4},
        { 3, 9,11,14},
    };
    
    int puzzle36[N][N] =
    {
        { 3, 8,15, 2},
        { 6, 1,10, 7},
        { 4,0,13,12},
        {11,14, 9, 5},
    };
    
    int puzzle37[N][N] =
    {
        { 7,0,14, 4},
        { 5,15, 6, 3},
        {11,12,13, 1},
        { 8, 2, 9,10},
    };
    
    int puzzle38[N][N] =
    {
        {11,10, 5, 7},
        {0, 8, 2, 6},
        {13,15,14, 3},
        {12, 1, 9, 4},
    };
    
    int puzzle39[N][N] =
    {
        {12,10, 3,13},
        {15, 1,0, 6},
        { 7,11, 8, 9},
        { 4, 5, 2,14},
    };
    
    int puzzle40[N][N] =
    {
        { 8,0, 9,13},
        {11,14,12, 6},
        { 2,15, 1, 3},
        {10, 4, 7, 5},
    };
    
    int puzzle41[N][N] =
    {
        { 1, 2, 8,11},
        { 7,12, 6,0},
        { 5,15,10, 4},
        {14,13, 3, 9},
    };
    
    int puzzle42[N][N] =
    {
        { 4, 7,14, 9},
        { 5,11, 8, 3},
        {0, 1,12, 2},
        {10,13, 6,15},
    };
    
    int puzzle43[N][N] =
    {
        { 7,10,12, 9},
        { 2,15,0, 1},
        { 3,14, 5, 4},
        {11, 6, 8,13},
    };
    
    int puzzle44[N][N] =
    {
        {13,14, 6,0},
        { 7, 2, 5,10},
        {15,11, 4,12},
        { 9, 3, 8, 1},
    };
    
    int puzzle45[N][N] =
    {
        {13, 9, 6, 4},
        {11,0, 3, 5},
        { 2, 7, 1,10},
        {12, 8,15,14},
    };
    
    int puzzle46[N][N] =
    {
        {11, 9,10,14},
        { 4, 8,15, 6},
        { 2,13,12,0},
        { 5, 3, 1, 7},
    };
    
    int puzzle47[N][N] =
    {
        { 3,12, 9,13},
        {15,11,10, 4},
        { 8, 5,0,14},
        { 1, 6, 7, 2},
    };
    
    int puzzle48[N][N] =
    {
        {13,14, 1, 4},
        { 9, 2,10, 8},
        {0, 7, 5,11},
        {12,15, 3, 6},
    };
    
    int puzzle49[N][N] =
    {
        { 7, 3,12, 4},
        {10,0,13, 5},
        { 9,14, 8, 6},
        {11,15, 2, 1},
    };
    
    int puzzle50[N][N] =
    {
        {10, 4, 1,12},
        { 2, 3,13,11},
        { 9, 5, 8, 6},
        {14,0,15, 7},
    };
    
    int puzzle51[N][N] =
    {
        {13,14, 3, 8},
        { 5, 2,12, 1},
        {11,10, 6, 4},
        { 9,0, 7,15},
    };
    
    int puzzle52[N][N] =
    {
        {12, 8,0,11},
        { 4,13, 5, 2},
        { 3, 7, 1,15},
        {14, 6,10, 9},
    };
    
    int puzzle53[N][N] =
    {
        {14, 6, 8, 4},
        {10,0, 2, 1},
        {15, 5, 9,12},
        {11, 3,13, 7},
    };
    
    int puzzle54[N][N] =
    {
        { 7, 6,11, 4},
        { 1,15, 9,13},
        { 3, 5, 8,14},
        { 2,12,0,10},
    };
    
    int puzzle55[N][N] =
    {
        { 3, 9, 4, 5},
        {15,0,13, 7},
        {10, 1, 8, 2},
        {14,12,11, 6},
    };
    
    int puzzle56[N][N] =
    {
        {10,0,15, 1},
        { 9, 7, 2, 6},
        {11, 4, 5,12},
        {13,14, 8, 3},
    };
    
    int puzzle57[N][N] =
    {
        { 8,12, 2, 9},
        {13, 4,10, 6},
        { 3, 5,11, 7},
        {0,14,15, 1},
    };
    
    int puzzle58[N][N] =
    {
        { 9,10, 7, 8},
        {15,13,14, 5},
        {0,11, 3, 4},
        { 6, 1, 2,12},
    };
    
    int puzzle59[N][N] =
    {
        {0,13, 8, 2},
        {15,11,14, 9},
        { 3, 5, 1, 4},
        {12,10, 6, 7},
    };
    
    int puzzle60[N][N] =
    {
        { 9, 8, 2,11},
        {15, 4,12, 3},
        { 5, 7,0, 1},
        {10,13, 6,14},
    };
    
    int puzzle61[N][N] =
    {
        {0,13, 7, 6},
        { 1, 3,12, 4},
        {11, 2, 9,10},
        {15,14, 5, 8},
    };
    
    int puzzle62[N][N] =
    {
        { 2,0,12,10},
        { 5, 1, 8, 3},
        { 7,13, 6, 9},
        {15,14,11, 4},
    };
    
    int puzzle63[N][N] =
    {
        { 8,0,13, 7},
        { 1, 5,11, 4},
        {12,14, 9,15},
        { 3, 6,10, 2},
    };
    
    int puzzle64[N][N] =
    {
        { 8, 3, 9,15},
        {0, 7, 4, 2},
        {14, 1,11, 5},
        {10, 6,12,13},
    };
    
    int puzzle65[N][N] =
    {
        { 2,11, 1,12},
        { 7,14, 3, 6},
        { 9,10,0, 5},
        { 8,15, 4,13},
    };
    
    int puzzle66[N][N] =
    {
        {15,11, 1,14},
        { 2, 3,0,13},
        { 6, 4,10,12},
        { 8, 7, 9, 5},
    };
    
    int puzzle67[N][N] =
    {
        {11, 4, 6,15},
        { 5, 9, 8, 2},
        { 1,10,14,12},
        {0, 3,13, 7},
    };
    
    int puzzle68[N][N] =
    {
        {14, 7, 2, 9},
        {15,10,11, 8},
        { 6, 1, 4,0},
        { 5, 3,12,13},
    };
    
    int puzzle69[N][N] =
    {
        { 4, 8,14,11},
        {12, 6, 7,13},
        {15, 5,0, 2},
        { 9, 1,10, 3},
    };
    
    int puzzle70[N][N] =
    {
        { 1, 9,0,10},
        {11, 6, 5,12},
        { 2,14, 8, 4},
        { 3,13, 7,15},
    };
    
    int puzzle71[N][N] =
    {
        {15,12,0,10},
        { 4, 9,14, 6},
        { 8, 1,13, 3},
        { 5,11, 2, 7},
    };
    
    int puzzle72[N][N] =
    {
        { 7,11, 5, 4},
        {12,0, 6,13},
        { 1, 8,14, 3},
        { 2, 9,15,10},
    };
    
    int puzzle73[N][N] =
    {
        { 8, 1, 3,11},
        { 7,14, 2, 9},
        { 5,12,15,0},
        {10,13, 4, 6},
    };
    
    int puzzle74[N][N] =
    {
        {14,0, 9, 7},
        { 8,12,11,13},
        {15, 2, 5, 3},
        {10, 1, 6, 4},
    };
    
    int puzzle75[N][N] =
    {
        {15, 2,10,14},
        { 8, 6, 5, 7},
        { 3,0,11, 9},
        {12,13, 4, 1},
    };
    
    int puzzle76[N][N] =
    {
        { 9, 6,13, 7},
        { 8,0,12,10},
        { 4,14,15, 2},
        { 3, 5, 1,11},
    };
    
    int puzzle77[N][N] =
    {
        { 2,15, 3,0},
        {13, 4, 8, 7},
        {11,10, 1, 5},
        { 6,14,12, 9},
    };
    
    int puzzle78[N][N] =
    {
        {15, 9,11, 3},
        {12, 7,13, 1},
        { 5, 2, 8, 4},
        {10,14, 6,0},
    };
    
    int puzzle79[N][N] =
    {
        { 2, 6,13, 7},
        { 8, 3,12, 1},
        {10,0,11, 9},
        { 5, 4,15,14},
    };
    
    int puzzle80[N][N] =
    {
        { 1,0, 7, 4},
        { 9,12,15, 3},
        { 5,14, 2, 6},
        {10, 8,13,11},
    };
    
    int puzzle81[N][N] =
    {
        {13, 2, 9,0},
        {12,11,15, 3},
        { 6,14,10, 4},
        { 5, 8, 7, 1},
    };
    
    int puzzle82[N][N] =
    {
        { 4, 8, 2, 7},
        { 6, 9,0,10},
        {14,12,11, 5},
        { 3,13,15, 1},
    };
    
    int puzzle83[N][N] =
    {
        { 1, 5,12,13},
        { 8, 3, 9, 4},
        {11,15, 7,14},
        {10,0, 2, 6},
    };
    
    int puzzle84[N][N] =
    {
        {10, 2, 1, 5},
        { 3, 9, 4,12},
        { 7,0,13,15},
        {14, 8,11, 6},
    };
    
    int puzzle85[N][N] =
    {
        { 8,10,14, 5},
        { 6,11,0, 3},
        {15, 4, 9, 7},
        { 2, 1,12,13},
    };
    
    int puzzle86[N][N] =
    {
        {13, 5, 2,14},
        {10,11, 1, 3},
        {12, 9,0, 8},
        { 7, 4,15, 6},
    };
    
    int puzzle87[N][N] =
    {
        { 6, 3,10,0},
        { 5,15, 8,12},
        { 1, 9, 7, 2},
        {13,11, 4,14},
    };
    
    int puzzle88[N][N] =
    {
        { 8, 1,13,15},
        {12, 4,14,10},
        { 7, 3, 9, 6},
        { 2,0, 5,11},
    };
    
    int puzzle89[N][N] =
    {
        { 6, 5, 2,14},
        {15, 1, 9, 3},
        { 4, 7, 8,12},
        {10,11,13,0},
    };
    
    int puzzle90[N][N] =
    {
        {11, 1,10, 4},
        {12,14,15, 2},
        { 7, 6, 9, 3},
        { 8, 5,13,0},
    };
    
    int puzzle91[N][N] =
    {
        {13, 6, 8,14},
        {15, 9, 1,10},
        {12,11, 3, 7},
        {0, 2, 5, 4},
    };
    
    int puzzle92[N][N] =
    {
        {12, 6,10, 1},
        { 7,11, 2,14},
        { 3,15, 9,13},
        { 5,0, 4, 8},
    };
    
    int puzzle93[N][N] =
    {
        {13, 2,11, 7},
        {15, 4, 1, 6},
        {10, 5, 8,12},
        {14,0, 3, 9},
    };
    
    int puzzle94[N][N] =
    {
        {14, 2,12, 3},
        { 7,0, 1, 4},
        {13, 5,11, 9},
        {10, 8, 6,15},
    };
    
    int puzzle95[N][N] =
    {
        {15,10, 5,0},
        { 3, 8, 6,13},
        {12,14, 2, 9},
        {11, 7, 1, 4},
    };
    
    int puzzle96[N][N] =
    {
        { 4, 8,0, 3},
        { 6, 2,15,11},
        {13,12, 1,14},
        { 9, 5, 7,10},
    };
    
    int puzzle97[N][N] =
    {
        { 6, 9,15,14},
        {0, 3, 1, 7},
        { 8,12, 4, 2},
        { 5,13,10,11},
    };
    
    int puzzle98[N][N] =
    {
        {11, 3, 6,10},
        { 7, 8,0, 1},
        {13,14, 4, 2},
        {12, 9,15, 5},
    };
    
    int puzzle99[N][N] =
    {
        { 8, 2, 5, 4},
        { 6,13,12, 3},
        {15, 7,11,0},
        {10,14, 9, 1},
    };
    
    int puzzle100[N][N] =
    {
        { 4,0, 5,10},
        {11, 7, 9,12},
        { 1, 8,14,15},
        { 3,13, 6, 2},
    };
    
    int puzzle101[N][N] =
    {
        { 6, 2, 1,14},
        { 9, 7,13, 5},
        {10,12,15, 4},
        { 8,11,0, 3},
    };
    
    int puzzle102[N][N] =
    {
        {11, 5,10, 7},
        { 1,0, 6, 3},
        { 4, 9,15, 2},
        {13,12,14, 8},
    };
    
    int puzzle103[N][N] =
    {
        {15, 2,14, 8},
        { 9, 5,13, 1},
        { 4,11,12, 6},
        {0,10, 3, 7},
    };
    
    int puzzle104[N][N] =
    {
        {10,12, 8, 4},
        {15,14,13,11},
        { 3, 1, 5, 2},
        { 9, 7,0, 6},
    };
    
    int puzzle105[N][N] =
    {
        { 3, 5,0,14},
        {15,12, 2,11},
        { 8, 7, 1, 6},
        { 9,10, 4,13},
    };
    
    int puzzle106[N][N] =
    {
        {10, 9, 2, 3},
        {15, 1,14, 6},
        {13,12, 7,11},
        { 8,0, 5, 4},
    };
    
    int puzzle107[N][N] =
    {
        { 2,14, 7, 8},
        { 1,0, 4, 6},
        {11, 9, 5, 3},
        {12,10,13,15},
    };
    
    int puzzle108[N][N] =
    {
        {0,15, 8, 3},
        {12,13, 9, 1},
        {10, 2,14, 7},
        {11, 4, 6, 5},
    };
    
    int puzzle109[N][N] =
    {
        {12, 6, 8, 5},
        {13, 9, 1,11},
        { 4, 7, 3,0},
        { 2,14,10,15},
    };
    
    int puzzle110[N][N] =
    {
        {15, 1, 7,11},
        { 3, 6,13,12},
        { 8,10, 9,0},
        {14, 5, 2, 4},
    };
    
    int puzzle111[N][N] =
    {
        { 6, 7,10, 9},
        { 2, 8,15,0},
        {14, 3, 5,13},
        { 1,11, 4,12},
    };
    
    int puzzle112[N][N] =
    {
        { 3, 7,0, 9},
        {13,12,10, 5},
        {11,14, 2, 1},
        { 4,15, 6, 8},
    };
    
    int puzzle113[N][N] =
    {
        { 7,12,13, 3},
        { 8,0, 6,11},
        {14, 4,15, 5},
        { 9, 2, 1,10},
    };
    
    int puzzle114[N][N] =
    {
        { 2,0, 6, 3},
        {15, 8, 7,13},
        { 1, 4, 5,11},
        {14,12,10, 9},
    };
    
    int puzzle115[N][N] =
    {
        {12, 7, 9, 4},
        { 5, 3,14,0},
        {13, 6, 1,15},
        {11,10, 2, 8},
    };
    
    int puzzle116[N][N] =
    {
        {14,12,10, 6},
        { 2, 9, 4,13},
        {15, 3,0, 5},
        { 7, 8,11, 1},
    };
    
    int puzzle117[N][N] =
    {
        {14, 5, 8, 1},
        { 4, 3,10,11},
        {13, 2, 7,0},
        { 9,15, 6,12},
    };
    
    int puzzle118[N][N] =
    {
        {12, 2,10, 3},
        { 1, 5,11, 7},
        {15, 6, 9,0},
        {14, 8, 4,13},
    };
    
    int puzzle119[N][N] =
    {
        { 3,11,14,13},
        { 4, 9, 8,12},
        { 5,0,10, 6},
        { 2, 1, 7,15},
    };
    
    int puzzle120[N][N] =
    {
        {0, 9, 7, 2},
        {14, 8,10,13},
        { 3, 4, 1, 5},
        {11, 6,12,15},
    };
    
    int puzzle121[N][N] =
    {
        {15, 9, 4, 7},
        {11, 3,10, 5},
        { 1, 8,14, 2},
        {12,0, 6,13},
    };
    
    int puzzle122[N][N] =
    {
        { 7,14, 5, 2},
        {15, 1,10,12},
        { 9, 3,13,0},
        { 8, 4,11, 6},
    };
    
    int puzzle123[N][N] =
    {
        { 5,0, 9, 6},
        {11,15,12, 7},
        {13, 1, 4,14},
        {10, 3, 2, 8},
    };
    
    int puzzle124[N][N] =
    {
        { 1,15, 9,14},
        { 2, 8,11, 6},
        {12,0, 4, 7},
        { 5, 3,10,13},
    };
    
    int puzzle125[N][N] =
    {
        { 7, 5,12, 9},
        {13, 4, 6,15},
        { 8,14, 3, 1},
        {11, 2,0,10},
    };
    
    int puzzle126[N][N] =
    {
        { 8,13,15, 4},
        { 3,12,0, 9},
        { 5, 1, 7,11},
        { 6,14,10, 2},
    };
    
    int puzzle127[N][N] =
    {
        { 1,11,15, 5},
        { 2,13, 9, 6},
        {12,14, 3, 4},
        { 8,0, 7,10},
    };
    
    isSolvable(puzzle0)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle1)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle2)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle3)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle4)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle5)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle6)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle7)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle8)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle9)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle10)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle11)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle12)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle13)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle14)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle15)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle16)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle17)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle18)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle19)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle20)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle21)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle22)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle23)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle24)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle25)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle26)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle27)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle28)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle29)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle30)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle31)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle32)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle33)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle34)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle35)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle36)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle37)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle38)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle39)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle40)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle41)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle42)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle43)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle44)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle45)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle46)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle47)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle48)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle49)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle50)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle51)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle52)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle53)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle54)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle55)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle56)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle57)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle58)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle59)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle60)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle61)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle62)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle63)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle64)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle65)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle66)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle67)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle68)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle69)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle70)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle71)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle72)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle73)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle74)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle75)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle76)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle77)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle78)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle79)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle80)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle81)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle82)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle83)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle84)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle85)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle86)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle87)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle88)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle89)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle90)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle91)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle92)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle93)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle94)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle95)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle96)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle97)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle98)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle99)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle100)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle101)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle102)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle103)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle104)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle105)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle106)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle107)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle108)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle109)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle110)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle111)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle112)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle113)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle114)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle115)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle116)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle117)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle118)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle119)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle120)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle121)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle122)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle123)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle124)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle125)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle126)? flag = "1" + flag : flag = "0" + flag;
    isSolvable(puzzle127)? flag = "1" + flag : flag = "0" + flag;
    
    std::cout<<"flag = " + flag;
    return 0;
}

Идем опять в python, вставляем полученный результат и строчку из описания к таску, получаем конечный флаг:

flag = 10101101001011000100110010010100110111101001100000101101111110001001010011111001001001111110111111101010011111010100100001010000 
print('SharifCTF{%016x}' % int(flag, 2))

Вывод: SharifCTF{ad2c4c94de982df894f927efea7d4850}
Но что такое, почему-то флаг не подходит!? Еще раз читаем описание, 1 if the puzzle is soluble и 0 if the puzzle is unsoluble. Вроде все верно?
В сотый раз прочитав описание замечаем, что в приведенном в описании примере функция возвращает 0 если пазл решаемый:

def is_soluble(i):
     return 0

Получается, что первая часть описания противоречит второй? Странно, но попробуем, а вдруг? Или переписываем наш код или тупо меняем в Notepad++ все нули на единицы и наоборот (естественно я сделал вторым вариантом) и снова пробуем получить флаг:

flag = '01010010110100111011001101101011001000010110011111010010000001110110101100000110110110000001000000010101100000101011011110101111'
print('SharifCTF{%016x}' % int(flag, 2))

Пробуем сдать и ура, в этот раз флаг подошел.
Флаг: SharifCTF{52d3b36b2167d2076b06d8101582b7af}


Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *