defarnold_transform(image): """Perform one iteration of the Arnold transform on the image.""" N = image.shape[0] new_image = np.zeros_like(image) for x inrange(N): for y inrange(N): new_x = (x + y) % N new_y = (x + 2 * y) % N new_image[new_x, new_y] = image[x, y] return new_image
defsave_images(image, max_iterations, output_prefix): """Save images after each iteration of the Arnold transform.""" transformed_image = np.copy(image) for i inrange(1, max_iterations + 1): transformed_image = arnold_transform(transformed_image) output_filename = f"compute/{i}.png" cv2.imwrite(output_filename, transformed_image) print(f"Saved {output_filename}")
# Load the image input_image_path = 'img/5.png'# Replace with your input image path image = cv2.imread(input_image_path)
if image isNone: raise ValueError("Image not found or unable to load image.")
# Number of iterations and output prefix max_iterations = 256 output_prefix = ''
# Save transformed images save_images(image, max_iterations, output_prefix)
imgs = [] for i inrange(256): img = Image.open(f"compute/{i}.png") img = np.array(img) imgs.append(img)
write_byte = [] for i inrange(802): img = Image.open(f"img/{i}.png") img = np.array(img) for j inrange(256): if np.array_equal(img, imgs[j]): write_byte.append(j) break
withopen("flag", "wb") as f: f.write(bytes(write_byte))