Informations

  • Catégorie : Programmation (Misc)
  • Niveau : Easy
  • Auteur : Hiruko
  • Flag : MB{D0y0uL0v3R0t4t1on?}

Intitulé

Plongé dans un environnement mystérieux et labyrinthique, vous êtes confronté à une série de cubes en constante transformation. Chaque cube représente une étape à franchir, une rotation à comprendre et un test à surmonter.

Votre objectif est de résoudre des énigmes basées sur des matrices en rotation, à chaque niveau le défi s'intensifie. Votre seule chance de vous échapper ? Répondre correctement en manipulant ces cubes, avec précision et à la vitesse de la lumière. Le temps et les rotations sont contre vous.


Write-up

import socket import numpy as np import re ADRESSE = '127.0.0.1' PORT = 6789 ROTATION = ["0", "90", "180", "270", "360"] ROTATION_COUNT = { "0": 0, "90": -1, "180": -2, "270": -3, "360": 0 } def parse_cube(cube_string): rows = cube_string.strip().split("\n") return [[int(num) for num in row.split()] for row in rows] def rotate_cube(cube, angle=90, clockwise=True): size = len(cube) rotated = cube angle = int(angle) rotations = (angle // 90) % 4 if clockwise: rotations = (4 - rotations) % 4 for _ in range(rotations): rotated = [[rotated[j][size - 1 - i] for j in range(size)] for i in range(size)] return rotated def main(): # Connect to the server client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect((ADRESSE, PORT)) data = client.recv(2048).decode() print(data) # Parse the cube matrix and rotate it matrix_pattern = re.compile(r">>> Rotate this cube:\s*((?:\d+\s+\d+\s+\d+\n?)+)") match = matrix_pattern.search(data) matrix = parse_cube(match.group(1)) rotated_matrix = rotate_cube(matrix, "90") # Send the rotated matrix to the server client.send(str(rotated_matrix).encode()) data = client.recv(1024).decode() print(data) # STEP 2 with angle matrix_pattern = re.compile(r"° :\s*((?:\d+\s+)*\d+\n?)+") degree_pattern = re.compile(r">>> Rotate this cube (\d{1,3})°") match = matrix_pattern.search(data) match_degree = degree_pattern.search(data) matrix = parse_cube(match.group(1)) rotation_angle = match_degree.group(1) rotated_matrix = rotate_cube(matrix, rotation_angle) # Send the rotated matrix to the server client.send(str(rotated_matrix).encode()) data = client.recv(1024).decode() print(data) # STEP 3 with angle with clowise matrix_pattern = re.compile(r" :\s*((?:\d+\s+)*\d+\n?)+") degree_pattern = re.compile(r">>> Rotate this cube (\d{1,3})°") clockwise_pattern = re.compile(r"clockwise (True|False)") match = matrix_pattern.search(data) match_degree = degree_pattern.search(data) match_clockwise = clockwise_pattern.search(data) matrix = parse_cube(match.group(1)) rotation_angle = match_degree.group(1) clockwise = match_clockwise.group(1) rotated_matrix = rotate_cube(matrix, rotation_angle, clockwise) # Send the rotated matrix to the server client.send(str(rotated_matrix).encode()) data = client.recv(1024).decode() print(data) if __name__ == "__main__": main()