Created
August 22, 2020 10:34
-
-
Save 0awawa0/3f6514015f1ad439f95e549aa820dc8e to your computer and use it in GitHub Desktop.
This file contains 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
from PIL import Image | |
from morse_decode import morse_decode | |
from zipfile import ZipFile | |
from os import chdir | |
def parse_image_to_morse(pixels, width, height, space_color, sign_color): | |
code = "" | |
for x in range(1, height, 2): | |
char_code = "" | |
counter = 0 | |
for y in range(1, width): | |
if rgb_to_int(pixels[y, x]) == sign_color: | |
counter += 1 | |
else: | |
if counter == 3: | |
char_code += "-" | |
if counter == 1: | |
char_code += "." | |
counter = 0 | |
code += char_code + " " | |
return code | |
def rgb_to_int(color): | |
return (color[0] << 8 | color[1]) << 8 | color[2] | |
for i in range(999, 0, -1): | |
image = Image.open("pwd.png") | |
pixels = image.load() | |
space_color = rgb_to_int(pixels[0, 0]) | |
sign_color = rgb_to_int(pixels[1, 1]) | |
password = morse_decode(parse_image_to_morse(pixels, image.width, image.height, space_color, sign_color)) | |
print(f"{i} Password is: {password}") | |
ZipFile(f"flag_{i}.zip").extractall(pwd=password.encode()) | |
chdir("./flag/") | |
image.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment