import sys def readlsb(byte): “”“Extracts the least significant bit from a byte.”“”…
- User
import sys
def read_lsb(byte): “”“Extracts the least significant bit from a byte.”“” return byte & 0x01
def bytes_to_int(byte_list): “”“Converts a list of bytes to an integer.”“” result = 0 for bit in reversed(byte_list): # Reversing the bit order to match the specification result = (result << 1) | bit return result
def extract_hidden_data(input_file, output_file): try: with open(input_file, “rb”) as f:
Skip the first 100 bytes as they don’t contain hidden info
f.seek(100)
Read bytes and process indicator
indicator = [] for _ in range(64): byte = f.read(1) if not byte: raise ValueError(“Reached end of file unexpectedly while reading indicator.”) indicator.append(read_lsb(byte[0]))
Checking the indicator after reversing the order of bits for each byte
indicator_value = bytes_to_int(indicator) if indicator_value != 0xa5a5a5a5a5a5a5a5: raise ValueError(“No steganographic indicator found or incorrect sequence.”)
Process the size of the hidden data
size_bits = [] for _ in range(27): byte = f.read(1) if not byte: raise ValueError(“Reached end of file unexpectedly while reading size.”) size_bits.append(read_lsb(byte[0]))
hidden_size = bytes_to_int(size_bits)
Extract the hidden data
hidden_data = [] for _ in range(hidden_size * 8): byte = f.read(1) if not byte: raise ValueError(“Reached end of file unexpectedly while reading hidden data.”) hidden_data.append(read_lsb(byte[0]))
Convert bits to bytes correctly according to specification
hidden_bytes = [] for i in range(0, len(hidden_data), 8): byte = bytes_to_int(hidden_data[i:i+8]) hidden_bytes.append(byte)
Write the extracted hidden data to the output file
with open(output_file, “wb”) as out: out.write(bytearray(hidden_bytes))
except Exception as e: print(f"Failed to extract hidden data: {e}“)
def main(): if len(sys.argv) != 3: print(“Usage: ./extract_stego.py <input_file> <output_file>”) sys.exit(1)
input_file, output_file = sys.argv[1], sys.argv[2] extract_hidden_data(input_file, output_file) print(f"Hidden data extracted to {output_file}.”)
if name == “main”: main() Write a README for the above code which minimally contains your name, B-number, programming language you used and how to compile/execute your program. Additionally, it can contain the following: • The status of your program (especially, if not fully complete). • A description of how your code works, if that is not completely clear by reading the code (note that this should not be necessary, ideally your code should be self-documenting). • Possibly a log of test cases which work and which don’t work. • Any other material you believe is relevant to the grading of your project.
- Assistant
README for Stego Extractor Program
Author Information
- Name: [Your Full Name]
- B-Number: [Your B-Number]
Program Language
This program is implemented in Python.
How to Execute