Created
December 1, 2024 13:59
-
-
Save fern89/347474eb9f6b4a3f72d8ce4219adf26c to your computer and use it in GitHub Desktop.
Tool to instasolve ctf chals that involve finding colour differences of like 1 shade in rgb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from PIL import Image | |
| import sys | |
| def shift_and_xor(image_path, output_path, threshold): | |
| img = Image.open(image_path) | |
| img_array = np.array(img) | |
| shifted = np.zeros_like(img_array) | |
| shifted[1:, 1:] = img_array[:-1, :-1] | |
| result = img_array ^ shifted | |
| result_gray = np.dot(result[..., :3], [1/3, 1/3, 1/3]) | |
| result_binary = (result_gray > threshold).astype(np.uint8) * 255 | |
| result_img = Image.fromarray(result_binary) | |
| result_img.save(output_path) | |
| print(f"Saved to {output_path}") | |
| if len(sys.argv) != 4 and len(sys.argv) != 3: | |
| print("Usage: [input] [output] [threshold (default = 30)]") | |
| elif len(sys.argv) == 4: | |
| shift_and_xor(sys.argv[1], sys.argv[2], int(sys.argv[3])) | |
| else: | |
| shift_and_xor(sys.argv[1], sys.argv[2], 30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment