mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-06-28 03:06:14 +02:00
Introduce a new argument in a2bits_list in order to specify the encoding of the string (unicode)
This commit is contained in:
parent
49964d4f16
commit
5f5c07493c
6 changed files with 77 additions and 28 deletions
|
@ -43,22 +43,31 @@ class TestLSB(unittest.TestCase):
|
|||
secret = lsb.hide("./tests/sample-files/Lenna.png", "")
|
||||
|
||||
def test_hide_and_reveal(self):
|
||||
messages_to_hide = ['🍕', 'a', 'foo', 'Hello World!', ':Python:']
|
||||
messages_to_hide = ['a', 'foo', 'Hello World!', ':Python:']
|
||||
for message in messages_to_hide:
|
||||
secret = lsb.hide("./tests/sample-files/Lenna.png", message)
|
||||
secret.save("./image.png")
|
||||
|
||||
clear_message = lsb.reveal("./image.png")
|
||||
|
||||
self.assertEqual(message, clear_message)
|
||||
|
||||
def test_hide_and_reveal_UTF32LE(self):
|
||||
messages_to_hide = 'I love 🍕 and 🍫!'
|
||||
secret = lsb.hide("./tests/sample-files/Lenna.png",
|
||||
messages_to_hide, 'UTF-32LE')
|
||||
secret.save("./image.png")
|
||||
|
||||
clear_message = lsb.reveal("./image.png", 'UTF-32LE')
|
||||
self.assertEqual(messages_to_hide, clear_message)
|
||||
|
||||
def test_with_transparent_png(self):
|
||||
messages_to_hide = ['🍕', 'a', 'foo', 'Hello World!', ':Python:']
|
||||
for message in messages_to_hide:
|
||||
secret = lsb.hide("./tests/sample-files/transparent.png", message)
|
||||
secret = lsb.hide("./tests/sample-files/transparent.png",
|
||||
message, 'UTF-32LE')
|
||||
secret.save("./image.png")
|
||||
|
||||
clear_message = lsb.reveal("./image.png")
|
||||
clear_message = lsb.reveal("./image.png", 'UTF-32LE')
|
||||
|
||||
self.assertEqual(message, clear_message)
|
||||
|
||||
|
@ -66,19 +75,19 @@ class TestLSB(unittest.TestCase):
|
|||
def test_manual_convert_rgb(self, input):
|
||||
message_to_hide = 'I love 🍕 and 🍫!'
|
||||
secret = lsb.hide("./tests/sample-files/Lenna-grayscale.png",
|
||||
message_to_hide)
|
||||
message_to_hide, 'UTF-32LE')
|
||||
|
||||
@patch('builtins.input', return_value='n')
|
||||
def test_refuse_convert_rgb(self, input):
|
||||
message_to_hide = 'I love 🍕 and 🍫!'
|
||||
with self.assertRaises(Exception):
|
||||
secret = lsb.hide("./tests/sample-files/Lenna-grayscale.png",
|
||||
message_to_hide)
|
||||
message_to_hide, 'UTF-32LE')
|
||||
|
||||
def test_auto_convert_rgb(self):
|
||||
message_to_hide = 'I love 🍕 and 🍫!'
|
||||
secret = lsb.hide("./tests/sample-files/Lenna-grayscale.png",
|
||||
message_to_hide, True)
|
||||
message_to_hide, 'UTF-32LE', True)
|
||||
|
||||
def test_with_text_file(self):
|
||||
text_file_to_hide = './tests/sample-files/lorem_ipsum.txt'
|
||||
|
|
|
@ -54,6 +54,18 @@ class TestLSBSet(unittest.TestCase):
|
|||
|
||||
self.assertEqual(message, clear_message)
|
||||
|
||||
def test_hide_and_reveal_UTF32LE(self):
|
||||
messages_to_hide = 'I love 🍕 and 🍫!'
|
||||
secret = lsbset.hide("./tests/sample-files/Lenna.png",
|
||||
messages_to_hide,
|
||||
generators.eratosthenes(),
|
||||
'UTF-32LE')
|
||||
secret.save("./image.png")
|
||||
|
||||
clear_message = lsbset.reveal("./image.png", generators.eratosthenes(),
|
||||
'UTF-32LE')
|
||||
self.assertEqual(messages_to_hide, clear_message)
|
||||
|
||||
def test_with_transparent_png(self):
|
||||
messages_to_hide = ["a", "foo", "Hello World!", ":Python:"]
|
||||
for message in messages_to_hide:
|
||||
|
@ -68,21 +80,22 @@ class TestLSBSet(unittest.TestCase):
|
|||
|
||||
@patch('builtins.input', return_value='y')
|
||||
def test_manual_convert_rgb(self, input):
|
||||
message_to_hide = "I love 🍕 and 🍫!"
|
||||
message_to_hide = "Hello World!"
|
||||
secret = lsbset.hide("./tests/sample-files/Lenna-grayscale.png",
|
||||
message_to_hide, generators.eratosthenes())
|
||||
|
||||
@patch('builtins.input', return_value='n')
|
||||
def test_refuse_convert_rgb(self, input):
|
||||
message_to_hide = "I love 🍕 and 🍫!"
|
||||
message_to_hide = "Hello World!"
|
||||
with self.assertRaises(Exception):
|
||||
secret = lsbset.hide("./tests/sample-files/Lenna-grayscale.png",
|
||||
message_to_hide, generators.eratosthenes())
|
||||
|
||||
def test_auto_convert_rgb(self):
|
||||
message_to_hide = "I love 🍕 and 🍫!"
|
||||
message_to_hide = "Hello World!"
|
||||
secret = lsbset.hide("./tests/sample-files/Lenna-grayscale.png",
|
||||
message_to_hide, generators.eratosthenes(), True)
|
||||
message_to_hide, generators.eratosthenes(),
|
||||
auto_convert_rgb=True)
|
||||
|
||||
def test_with_too_long_message(self):
|
||||
with open("./tests/sample-files/lorem_ipsum.txt") as f:
|
||||
|
|
|
@ -37,8 +37,23 @@ class TestTools(unittest.TestCase):
|
|||
bits = tools.a2bits("Hello World!")
|
||||
self.assertEqual(bits, '010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001')
|
||||
|
||||
def test_a2bits_list(self):
|
||||
def test_a2bits_list_UTF8(self):
|
||||
list_of_bits = tools.a2bits_list("Hello World!")
|
||||
self.assertEqual(list_of_bits, ['01001000',
|
||||
'01100101',
|
||||
'01101100',
|
||||
'01101100',
|
||||
'01101111',
|
||||
'00100000',
|
||||
'01010111',
|
||||
'01101111',
|
||||
'01110010',
|
||||
'01101100',
|
||||
'01100100',
|
||||
'00100001'])
|
||||
|
||||
def test_a2bits_list_UTF32LE(self):
|
||||
list_of_bits = tools.a2bits_list("Hello World!", 'UTF-32LE')
|
||||
self.assertEqual(list_of_bits, ['00000000000000000000000001001000',
|
||||
'00000000000000000000000001100101',
|
||||
'00000000000000000000000001101100',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue