1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import time
from PIL import Image, ImageDraw, ImageFont import threading import random import secrets
flag = "hgame{fake_flag}"
def generate_random_image(width, height): image = Image.new("RGB", (width, height), "white") pixels = image.load() for x in range(width): for y in range(height): red = random.randint(0, 255) green = random.randint(0, 255) blue = random.randint(0, 255) pixels[x, y] = (red, green, blue) return image
def draw_text(image, width, height, token): font_size = random.randint(16, 40) font = ImageFont.truetype("arial.ttf", font_size) text_color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) x = random.randint(0, width - font_size * len(token)) y = random.randint(0, height - font_size) draw = ImageDraw.Draw(image) draw.text((x, y), token, font=font, fill=text_color) return image
def xor_images(image1, image2): if image1.size != image2.size: raise ValueError("Images must have the same dimensions.") xor_image = Image.new("RGB", image1.size) pixels1 = image1.load() pixels2 = image2.load() xor_pixels = xor_image.load() for x in range(image1.size[0]): for y in range(image1.size[1]): r1, g1, b1 = pixels1[x, y] r2, g2, b2 = pixels2[x, y] xor_pixels[x, y] = (r1 ^ r2, g1 ^ g2, b1 ^ b2) return xor_image
def generate_unique_strings(n, length): unique_strings = set() while len(unique_strings) < n: random_string = secrets.token_hex(length // 2) unique_strings.add(random_string) return list(unique_strings)
random_strings = generate_unique_strings(len(flag), 8)
current_image = generate_random_image(120, 80) key_image = generate_random_image(120, 80)
def random_time(image, name): time.sleep(random.random()) image.save(".\\png_out\\{}.png".format(name))
for i in range(len(flag)): current_image = draw_text(current_image, 120, 80, flag[i]) threading.Thread(target=random_time, args=(xor_images(current_image, key_image), random_strings[i])).start()
|