The StaticMaker ™ utility converts any binary file into a video, suitable for use in … some application somewhere, probably. The default configuration is width=256, height=256.
The program works by: 1. Compressing the data 2. Padding to a size that is a multiple of (6*width*height) bits 3. Splitting the data into “subframes” of size (2*width*height) bits 4. Writes data to video frames, which each triplet of three consecutive subframes are written to the red, green, and blue channels of one frame, respectively Data written in row-major order 2 bits per pixel per channel THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
import hashlib from PIL import Image import numpy as np
defdecode_frames(frame_prefix, frame_count, width=256, height=256): channels = ['R', 'G', 'B'] bit_position = 4# Bit position(4or6) chosen based on successful MD5 checksum match, were taken bitpositions [2,4,6,8] data_bits = [] for frame_idx inrange(1, frame_count + 1): frame_path = f"{frame_prefix}{frame_idx:04d}.png" frame = Image.open(frame_path) frame = frame.convert("RGB") pixels = np.array(frame) # Extract the specified bits from each color channel r_channel = (pixels[:, :, 0] & (0b11 << bit_position)) >> bit_position g_channel = (pixels[:, :, 1] & (0b11 << bit_position)) >> bit_position b_channel = (pixels[:, :, 2] & (0b11 << bit_position)) >> bit_position # Flatten the channels and convert to bit strings for bits in r_channel.flatten(): data_bits.append(format(bits, '02b')) for bits in g_channel.flatten(): data_bits.append(format(bits, '02b')) for bits in b_channel.flatten(): data_bits.append(format(bits, '02b')) return''.join(data_bits)
defcheck_padding(data_bits, width, height): size = 6 * width * height print("The size is", size) actual_size = len(data_bits) print('The actual size is ', actual_size) if actual_size % size == 0: print("Multiple of size") # No padding to remove return data_bits # size was already in multiple so need for removing the padding. # Calculate the number of excess bits to remove padding_size = actual_size % size # Remove the excess bits data_bits = data_bits[:-padding_size] return data_bits
defbits_to_bytes(data_bits): byte_arr = bytearray() for i inrange(0, len(data_bits), 8): byte = data_bits[i:i+8] byte_arr.append(int(byte, 2)) returnbytes(byte_arr)
# Convert bits to bytes compressed_data = bits_to_bytes(data_bits)
output_path = 'extracted_data.bin' withopen(output_path, 'wb') as f: f.write(compressed_data) print("Extracted data saved.")
# Calculate and print MD5 checksum calculated_md5 = calculate_md5(compressed_data) print(f"MD5 checksum of extracted data after removing padding: {calculated_md5}")