def test_hide_reveal_string_inverse(string_to_hide): """Anything hidden by _hide_string is revealed by _reveal_string.""" clean_data = bytes(b'\x01' * 5000) stegs = Steganographer() stegs._header.data_len = len(string_to_hide.encode('utf-8')) revealed_string = stegs._reveal_string( stegs._hide_string(clean_data, string_to_hide)) assert revealed_string == string_to_hide
def test_exact_data_with_string_inverse(): """The string entered is the string returned. The storing data is the exact length needed.""" test_string = "This is a test String" stegs = Steganographer() stegs._header.data_len = len(test_string) blank_data = bytes(b'\x01' * len(test_string) * stegs._BYTELEN) revealed_string = stegs._reveal_string( stegs._hide_string(blank_data, test_string)) assert test_string == revealed_string
def test_short_data_with_string_inverse(): """When the data is too small, by a full byte, everything that can be returned is returned.""" test_string = "This is a test String" stegs = Steganographer() stegs._header.data_len = len(test_string) blank_data = bytes(b'\x01' * (len(test_string) * stegs._BYTELEN - stegs._BYTELEN)) revealed_string = stegs._reveal_string( stegs._hide_string(blank_data, test_string)) assert test_string[:-1] == revealed_string
def test_short_partial_data_string_inverse(): """When the data is too small, by a half byte, everything that can be returned is returned.""" test_string = "This is a test String" stegs = Steganographer() stegs._header.data_len = len(test_string) solution_string = test_string[:-1] + chr( ord(test_string[-1]) >> stegs._BYTELEN // 2 << stegs._BYTELEN // 2) blank_data = bytes( b'\x01' * (len(test_string) * stegs._BYTELEN - stegs._BYTELEN // 2)) revealed_string = stegs._reveal_string( stegs._hide_string(blank_data, test_string)) assert solution_string == revealed_string
def test_reveal_string(): """Returns a string representation of the data that was hidden in the test_data.""" solution = 'ABC' stegs = Steganographer() stegs._header.data_len = len(solution) test_data = bytearray(stegs._BYTELEN * 4) test_data[1] = 1 test_data[7] = 1 test_data[9] = 1 test_data[14] = 1 test_data[17] = 1 test_data[22] = 1 test_data[23] = 1 assert stegs._reveal_string(test_data) == solution