let templates = [
    [
        "X--X----",
        "-XXX-X--",
        "----X---",
        "----X---",
        "------XX",
        "----XX--",
        "X-------",
        "-XX--X--"
    ],
    [
        "---XX---",
        "----X-X-",
        "---XX---",
        "---X----",
        "-X------",
        "X----X-X",
        "--X--X--",
        "-X----XX"
    ],
    [
        "-X-X----",
        "---X-X--",
        "X-XX--X-",
        "--X-X---",
        "------X",
        "--------",
        "X-----X-",
        "-X-X---X"
    ],
    [
        "-XX-X---",
        "-----X--",
        "----X---",
        "-----X-X",
        "-X-X--X-",
        "-XX----X",
        "-X------",
        "XX------"
    ], [
        "----XX-X",
        "X-------",
        "--------",
        "-----XX-",
        "---X-X--",
        "-X---XX-",
        "-X-X----",
        "----XXX-"
    ], [
        "XX------",
        "-----X--",
        "-------X",
        "-X-X----",
        "X-X----X",
        "-X-X-X-X",
        "----X-X-",
        "-X------"
    ],
];
const squareSize = templates[0].length;

//convert to arrays for mutability
let temp = []
for (let n = 0; n < templates.length; n++) {
    temp.push([])
    for (let i = 0; i < squareSize; i++) {
        temp[n].push([]);
        for (let j = 0; j < squareSize; j++) {
            temp[n][i].push(templates[n][i][j] == "X" ? 1 : 0);

        }
    }
}
templates = temp;

const encodedMsg = "Р_НАЙА_СЛЗДЕ_ЛОСЖСТОИКНОЛЬЛЬТКУЮО__КЗАЕ_ДВАОКАЧОЖЗ_УЧАСМОДУ_ТЮЖЕ";


function rotateTemplate(template) {
    for (let i = 0; i < squareSize; i++) {
        for (let j = 0; j < i; j++) {
            let temp = template[i][j];
            template[i][j] = template[j][i];
            template[j][i] = temp;
        }
    }
    for (let i = 0; i < squareSize; i++) {
        for (let j = 0; j < squareSize / 2; j++) {
            let temp = template[i][j];
            template[i][j] = template[i][(squareSize - 1) - j];
            template[i][(squareSize - 1) - j] = temp;
        }
    }
}

for (let n = 0; n < templates.length; n++) {
    let out = ""
    for (let rot = 0; rot < 4; rot++) {
        for (let i = 0; i < squareSize; i++) {
            for (let j = 0; j < squareSize; j++) {
                if (templates[n][i][j]) {
                    out += encodedMsg[i * squareSize + j];
                }
            }
        }
        rotateTemplate(templates[n]);
    }
    console.log(out);
    console.log("=======");

}