stegosphere.utils module

class stegosphere.utils.File(data)

Bases: object

A superclass for handling file data in various formats. Provides common functionality for reading, saving, and reshaping data.

Parameters:

data (numpy.ndarray, str, list, or tuple) – The file data, either a NumPy array, file path, or list/tuple.

flush()

Reshapes the file data back to its original shape. Use if self.save is not sufficient for saving the result.

read(data)

Reads and returns data from various sources such as NumPy arrays, file paths, or lists/tuples.

Parameters:

data (str, numpy.ndarray, list, or tuple) – Data source, either a file path, NumPy array, or list/tuple.

Returns:

Data as a NumPy array.

Return type:

numpy.ndarray

save(path)

Saves the current data to the specified file path.

Parameters:

path (str) – File path where the data will be saved.

stegosphere.utils.binary_to_data(binary)

Converts binary string to data.

Parameters:

binary – Binary string to convert

Returns:

Data as bytes

stegosphere.utils.binary_to_file(binary_data, output_path)

Converts binary data back to a file.

Parameters:
  • binary_data – Binary data to convert

  • output_file_path – Path to save the output file

stegosphere.utils.check_type(data)

Check whether data is binary, hexadecimal or neither

Parameters:

data – data to be checked

Returns:

int, 0 meaning binary, 1 meaning hex, 2 meaning neither

stegosphere.utils.data_to_binary(data)

Converts data (string or bytes) to a binary string.

Parameters:

data – Data to convert

Returns:

Binary string

stegosphere.utils.file_to_binary(path)

Converts a file into its binary representation.

Parameters:

file_path – Path to the input file

Returns:

Binary data of the file

stegosphere.utils.generate_message_bits(extracted_bits, bits)
stegosphere.utils.hex_to_binary(data)

Convert hexadecimal str to binary str.

Parameters:

data – data to be converted

Returns:

binary data

stegosphere.utils.is_binary(data)

Check if string only contains binary data.

Parameters:

data – data to be checked

Returns:

bool

stegosphere.utils.parse_message(message, bits)
stegosphere.utils.prng_indices(length, key)