feat: add rizzfield challenge
This commit is contained in:
		
							parent
							
								
									cd79fe01d9
								
							
						
					
					
						commit
						242f9b8636
					
				
							
								
								
									
										13
									
								
								rizzfield/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								rizzfield/README.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
# Rizzfield
 | 
			
		||||
 | 
			
		||||
## Text
 | 
			
		||||
 | 
			
		||||
What's 9 + 10?
 | 
			
		||||
 | 
			
		||||
## Files
 | 
			
		||||
 | 
			
		||||
rizzfield.gif
 | 
			
		||||
 | 
			
		||||
## How to Deploy
 | 
			
		||||
 | 
			
		||||
N/A
 | 
			
		||||
							
								
								
									
										15
									
								
								rizzfield/SOLUTION.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								rizzfield/SOLUTION.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
## Difficulty
 | 
			
		||||
 | 
			
		||||
Medium++
 | 
			
		||||
 | 
			
		||||
## Category
 | 
			
		||||
 | 
			
		||||
Steg
 | 
			
		||||
 | 
			
		||||
## How To Solve
 | 
			
		||||
 | 
			
		||||
I changed the color of the 21th frame. What you can do, is randomize the entire palette of the 21th frame and the text should become visible.
 | 
			
		||||
 | 
			
		||||
## Flag
 | 
			
		||||
 | 
			
		||||
IGCTF{H3sGoTsTh3RiZz}
 | 
			
		||||
							
								
								
									
										42
									
								
								rizzfield/frame_destroyer.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								rizzfield/frame_destroyer.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,42 @@
 | 
			
		||||
from PIL import Image
 | 
			
		||||
import numpy as np
 | 
			
		||||
 | 
			
		||||
# Load the GIF
 | 
			
		||||
gif_path = "./garfield-garfield-meme-ezgif.com-added-text.gif"
 | 
			
		||||
gif = Image.open(gif_path)
 | 
			
		||||
 | 
			
		||||
# Define the color you want to replace (original text color) and the new color
 | 
			
		||||
original_text_color = (55, 126, 34)  # Replace with the actual color of the text in RGB
 | 
			
		||||
new_text_color = (255, 254, 253)           # Desired replacement color, e.g., black
 | 
			
		||||
 | 
			
		||||
# Function to find the indices of the top 5 closest colors in the palette
 | 
			
		||||
def find_closest_palette_color_indices(palette, target_color, num_colors=25):
 | 
			
		||||
    palette = np.array(palette).reshape(-1, 3)
 | 
			
		||||
    target_color = np.array(target_color)
 | 
			
		||||
    distances = np.sqrt(((palette - target_color) ** 2).sum(axis=1))
 | 
			
		||||
    # Get the indices of the closest colors
 | 
			
		||||
    return distances.argsort()[:num_colors]
 | 
			
		||||
 | 
			
		||||
# Extract frames and modify frame 21
 | 
			
		||||
frames = []
 | 
			
		||||
for i in range(gif.n_frames):
 | 
			
		||||
    gif.seek(i)
 | 
			
		||||
    new_frame = gif.convert("P", palette=Image.ADAPTIVE)  # Convert to palette mode
 | 
			
		||||
    
 | 
			
		||||
    if i == 20:
 | 
			
		||||
        # Get the palette and find the closest color indices for the original text color
 | 
			
		||||
        palette = new_frame.getpalette()
 | 
			
		||||
        closest_color_indices = find_closest_palette_color_indices(palette, original_text_color, num_colors=255)
 | 
			
		||||
        
 | 
			
		||||
        # Modify the palette at each of the closest color indices to the new color
 | 
			
		||||
        for idx in closest_color_indices:
 | 
			
		||||
            palette[idx*3:idx*3+3] = list(new_text_color)
 | 
			
		||||
        new_frame.putpalette(palette)
 | 
			
		||||
 | 
			
		||||
    # Append the modified (or unmodified) frame
 | 
			
		||||
    frames.append(new_frame)
 | 
			
		||||
 | 
			
		||||
# Save the modified GIF
 | 
			
		||||
output_path = "./modified_gif.gif"
 | 
			
		||||
frames[0].save(output_path, save_all=True, append_images=frames[1:], loop=0, duration=gif.info['duration'])
 | 
			
		||||
print(f"Modified GIF saved as {output_path}")
 | 
			
		||||
							
								
								
									
										37
									
								
								rizzfield/randomize_palette.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								rizzfield/randomize_palette.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
from PIL import Image
 | 
			
		||||
import random
 | 
			
		||||
 | 
			
		||||
# Load the GIF
 | 
			
		||||
gif_path = "./garfield-garfield-meme-ezgif.com-added-text.gif"
 | 
			
		||||
gif = Image.open(gif_path)
 | 
			
		||||
 | 
			
		||||
# Function to randomize the palette
 | 
			
		||||
def randomize_palette(palette):
 | 
			
		||||
    # Convert palette (a flat list) to a list of (R, G, B) tuples
 | 
			
		||||
    colors = [(palette[i], palette[i + 1], palette[i + 2]) for i in range(0, len(palette), 3)]
 | 
			
		||||
    # Shuffle the colors
 | 
			
		||||
    random.shuffle(colors)
 | 
			
		||||
    # Flatten the list back to the original format
 | 
			
		||||
    randomized_palette = [val for color in colors for val in color]
 | 
			
		||||
    return randomized_palette
 | 
			
		||||
 | 
			
		||||
# Extract frames and modify frame 21
 | 
			
		||||
frames = []
 | 
			
		||||
for i in range(gif.n_frames):
 | 
			
		||||
    gif.seek(i)
 | 
			
		||||
    new_frame = gif.convert("P", palette=Image.ADAPTIVE)  # Convert to palette mode
 | 
			
		||||
    
 | 
			
		||||
    if i == 20:
 | 
			
		||||
        # Get the palette of the frame and randomize it
 | 
			
		||||
        palette = new_frame.getpalette()
 | 
			
		||||
        randomized_palette = randomize_palette(palette)
 | 
			
		||||
        # Apply the randomized palette to the frame
 | 
			
		||||
        new_frame.putpalette(randomized_palette)
 | 
			
		||||
 | 
			
		||||
    # Append the modified (or unmodified) frame
 | 
			
		||||
    frames.append(new_frame)
 | 
			
		||||
 | 
			
		||||
# Save the modified GIF
 | 
			
		||||
output_path = "./randomized_palette_gif.gif"
 | 
			
		||||
frames[0].save(output_path, save_all=True, append_images=frames[1:], loop=0, duration=gif.info['duration'])
 | 
			
		||||
print(f"Modified GIF with randomized palette saved as {output_path}")
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								rizzfield/rizzfield.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								rizzfield/rizzfield.gif
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 3.2 MiB  | 
							
								
								
									
										
											BIN
										
									
								
								rizzfield/solution.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								rizzfield/solution.gif
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 3.2 MiB  | 
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user