def test_create_file(self):
     with open('filename.txt', 'w') as file:
         file.write('blablablablablablablablablablablabbl')
     LSBEncoder._check_the_opportunity_to_enter = \
         MagicMock(return_value=True)
     lsb = LSBEncoder(['filename.txt'], 'filename.txt', 0)
     result = lsb.create_new_wav()
     os.remove('filename.txt')
     self.assertIsNone(result)
 def test_describe_data(self):
     with open('filename.txt', 'w') as file:
         file.write('blablablablablablablablablablablabbl')
     LSBEncoder._check_the_opportunity_to_enter = \
         MagicMock(return_value=True)
     lsb = LSBEncoder(['filename.txt'], 'filename.txt', 0)
     result = lsb.describe_data_and_get_index(['0', '0', '0', '1'],
                                              0, 2)
     os.remove('filename.txt')
     self.assertIsInstance(result, int)
 def test_inscribe(self):
     with open('main_file.txt', 'w') as file:
         file.write('blablablablablablablablablablablabbl'*15000)
     with open('file.txt', 'w') as file2:
         file2.write('s')
     LSBEncoder._check_the_opportunity_to_enter = \
         MagicMock(return_value=True)
     LSBEncoder._create_new_byte_of_flag = MagicMock(return_value=42)
     LSBEncoder._create_new_byte_of_data = MagicMock(return_value=42)
     LSBEncoder.describe_data_and_get_index = MagicMock(return_value=1)
     lsb = LSBEncoder(['file.txt'], 'main_file.txt', 0)
     result = lsb.inscribe()
     os.remove('file.txt')
     os.remove('main_file.txt')
     self.assertIsNone(result)
Exemplo n.º 4
0
 def test_create_new_byte_of_data(self):
     byte = bytearray(b'\x00')
     pairs = ['00', '10', '11', '01', '00', '11', '10']
     i = 2
     expectation = 3
     result = LSBEncoder._create_new_byte_of_data(byte, pairs, i)
     self.assertEqual(result, expectation)
Exemplo n.º 5
0
 def test_create_description(self):
     test_pairs = ['00', '10', '11', '11', '01', '00', '10', '01']
     expectation = [
         '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1',
         '0', '0', '0'
     ]
     result = LSBEncoder._create_description(test_pairs, 16)
     self.assertEqual(result, expectation)
 def test_init(self):
     with open('filename.txt', 'w') as file:
         file.write('blablablablablablablablablablablablablablabla')
     try:
         lsb = LSBEncoder(['filename.txt'], 'filename.txt')
     except Exception:
         self.assertEqual(1, 1)
     os.remove('filename.txt')
 def test_create_new_byte_of_flag(self):
     description = ['0', '0', '0', '0', '0', '0', '0', '0', '0',
                    '0', '0', '0', '1', '0', '0', '0']
     byte = bytearray(b'\x00')
     i = 12
     expectation = 1
     result = LSBEncoder._create_new_byte_of_flag(byte, description, i)
     self.assertEqual(result, expectation)
 def test_get_bits_per_sample(self):
     expectation = 16
     string = ''
     for i in range(34):
         string += '\x00'
     string += '\x10\x00'
     result = LSBEncoder._get_bits_per_sample(bytearray(bytes(string, 'utf-8')))
     self.assertEqual(result, expectation)
 def test_chech_the_opportunity_to_enter(self):
     with open('filename.txt', 'w') as file:
         file.write('blablablablablablablabl')
     try:
         LSBEncoder(['filename.txt'], 'filename.txt')
     except Exception:
         self.assertEqual(1, 1)
     os.remove('filename.txt')
Exemplo n.º 10
0
 def test_init(self):
     with open('filename.txt', 'w') as file:
         file.write('blablablablablablablablablablablablablablabla')
     sample = LSBEncoder('filename.txt', 'filename.txt')
     os.remove('filename.txt')
     self.assertIsInstance(sample.main_file, bytearray)
     self.assertIsInstance(sample.inserted_file, bytearray)
     self.assertEqual(sample.index_of_start_of_data, 7)
     self.assertIsInstance(sample.bits_per_sample, int)
 def main(self):
     parser = self.parse_args(sys.argv[1:])
     if parser.encode and parser.decode:
         raise Exception("This keys shouldn't be used at the same time")
     if parser.encode:
         files = parser.file
         wav_path = ' '.join(parser.wav)
         if len(files) == 0 or len(wav_path) == 0:
             raise Exception('Not all arguments are specified. Try again!')
         lsb = LSBEncoder(files, wav_path)
         lsb.inscribe()
         lsb.create_new_wav()
         return
     if parser.decode:
         wav_path = ' '.join(parser.wav)
         if len(wav_path) == 0:
             raise Exception('Not all arguments are specified. Try again!')
         lsb = LSBDecoder(wav_path)
         lsb.get_hidden_information()
Exemplo n.º 12
0
 def main(self):
     if self.parser.encode and self.parser.decode:
         raise Exception("This keys shouldn't be used at the same time")
     if self.parser.encode:
         file_path = ' '.join(self.parser.file)
         wav_path = ' '.join(self.parser.wav)
         if len(file_path) == 0 or len(wav_path) == 0:
             raise Exception('Not all arguments are specified. Try again!')
         lsb = LSBEncoder(file_path, wav_path)
         lsb.inscribe()
         return
     if self.parser.decode:
         wav_path = ' '.join(self.parser.wav)
         if len(wav_path) == 0:
             raise Exception('Not all arguments are specified. Try again!')
         lsb = LSBDecoder(wav_path)
         lsb.get_hidden_information()
Exemplo n.º 13
0
 def test_define_filename(self):
     test_str = r'C:\Users\User\Desktop\filename.txt'
     result = LSBEncoder._define_filename(test_str)
     expectation = bytearray(bytes('filename.txt', 'utf-8'))
     self.assertEqual(result, expectation)