Skip to content

CubeRotation

CubeRotation

Category: Misc - Points: 212 - Solves: 17

Description:

Your text

Solution:
Dans ce challenge, nous devions executer une rotation de notre cube, la taille du cube s'incremente à chaques étapes.

Your text

Script de résolution en python :

import socket

def rotate(matrix, angle):
    # Applique rotation selon l'angle donné
    if angle == 90:
        return [list(row) for row in zip(*matrix[::-1])]
    elif angle == 180:
        return [row[::-1] for row in matrix[::-1]]
    elif angle == 270:
        return [list(row) for row in zip(*matrix)][::-1]
    else:
        raise ValueError("Angle non supporté")

def parse_matrix(data):
    lines = data.strip().split("\n")
    matrix_lines = [line.strip() for line in lines if line.strip() and all(c.isdigit() or c.isspace() for c in line)]
    matrix = [[int(n) for n in line.split()] for line in matrix_lines]
    return matrix

def extract_angle(data):
    if "90" in data:
        return 90
    elif "180" in data:
        return 180
    elif "270" in data:
        return 270
    else:
        raise ValueError("Aucun angle détecté")

def receive_until(s, marker=b">>>"):
    data = b""
    while marker not in data:
        chunk = s.recv(4096)
        if not chunk:
            break
        data += chunk
    return data.decode()

def main():
    host = "chall.m1ndbr34k.fr"
    port = 49681

    with socket.create_connection((host, port)) as s:
        while True:
            try:
                prompt = receive_until(s)
                print(prompt)

                if "Rotate this cube" in prompt:
                    angle = extract_angle(prompt)
                    matrix = parse_matrix(prompt)
                    rotated = rotate(matrix, angle)
                    response = str(rotated).replace(' ', '') + "\n"
                    print("Sending:", response.strip())
                    s.sendall(response.encode())
            except Exception as e:
                print("Disconnected or error:", e)
                break

if __name__ == "__main__":
    main()
FLAG
MB{D0y0uL0v3R0t4t1on?}