def decode(self):
     index = 0
     while index != len(self.data):
         if Stuff.get_bin_from_int(self.data[index]).startswith('1'):
             bound = int(Stuff.get_bin_from_int(self.data[index])[1:], 2)
             for i in range(bound):
                 self.result.append(self.data[index + 1])
             index += 2
         else:
             for i in range(self.data[index]):
                 index += 1
                 self.result.append(self.data[index])
             index += 1
     return self.result
Exemple #2
0
 def review_diff_bytes(self, diff_bytes: deque):
     if len(diff_bytes) != 0:
         while len(diff_bytes) > 127:
             self.result_data.append(127)
             for i in range(127):
                 self.result_data.append(diff_bytes.popleft())
         new_byte = Stuff.get_bin_from_int(len(diff_bytes))
         self.result_data.append(Stuff.get_int_from_bin(new_byte))
         for i in range(len(diff_bytes)):
             self.result_data.append(diff_bytes.popleft())
     return diff_bytes
 def inscribe(self):
     offset = bytes_per_sample = self.bits_per_sample // 8
     index = self.index_of_start_of_data + bytes_per_sample
     bytes_to_describe_length_of_data = 32
     bits_to_write = Stuff.get_bin_str_from_bytearray(self.pickled_files)
     list_of_pairs_to_write = list(bits_to_write)
     length_description = self._create_description(
         list_of_pairs_to_write, bytes_to_describe_length_of_data)
     bytes_to_describe_length_of_hash = 8
     current_hash = Stuff.get_hash(self.pickled_files)
     bits_of_hash = Stuff.get_bin_from_int(current_hash)
     hash_pairs = list(bits_of_hash)
     hash_description = self._create_description(
         hash_pairs, bytes_to_describe_length_of_hash)
     index = self.describe_flag_and_get_index(
         bytes_to_describe_length_of_data, length_description, index,
         offset)
     index = self.describe_flag_and_get_index(
         bytes_to_describe_length_of_hash, hash_description, index, offset)
     index = self.describe_data_and_get_index(hash_pairs, index, offset)
     self.describe_data_and_get_index(list_of_pairs_to_write, index, offset)
Exemple #4
0
    def inscribe(self):
        bytes_to_describe_length_of_name = 16
        bits_of_name = Stuff.get_bin_str_from_bytearray(self.inserted_name)
        # list_of_pairs_of_name = Stuff.split_in_two_bits(bits_of_name)
        list_of_pairs_of_name = list(bits_of_name)
        name_description = self._create_description(
            list_of_pairs_of_name, bytes_to_describe_length_of_name)
        bytes_to_describe_length_of_data = 32
        bits_to_write = Stuff.get_bin_str_from_bytearray(
            self.inserted_file)  # строка которую записываем
        # list_of_pairs_to_write = Stuff.split_in_two_bits(bits_to_write)
        list_of_pairs_to_write = list(bits_to_write)
        length_description = self._create_description(
            list_of_pairs_to_write, bytes_to_describe_length_of_data)
        bytes_to_describe_length_of_hash = 8
        bits_of_hash = Stuff.get_bin_from_int(self.inserted_hash)
        # hash_pairs = Stuff.split_in_two_bits(bits_of_hash)
        hash_pairs = list(bits_of_hash)
        hash_description = self._create_description(
            hash_pairs, bytes_to_describe_length_of_hash)
        offset = bytes_per_sample = self.bits_per_sample // 8
        index = self.index_of_start_of_data + bytes_per_sample
        index = self.describe_flag_and_get_index(
            bytes_to_describe_length_of_data, length_description, index,
            offset)
        index = self.describe_flag_and_get_index(
            bytes_to_describe_length_of_name, name_description, index, offset)
        index = self.describe_flag_and_get_index(
            bytes_to_describe_length_of_hash, hash_description, index, offset)
        index = self.describe_data_and_get_index(hash_pairs, index, offset)

        index = self.describe_data_and_get_index(list_of_pairs_of_name, index,
                                                 offset)
        self.describe_data_and_get_index(list_of_pairs_to_write, index, offset)
        with open('new_wav.wav', 'wb') as file:
            file.write(self.main_file)
 def test_get_bin_from_int(self):
     byte = 5
     result = LSBStuff.get_bin_from_int(byte)
     self.assertEqual(result, '00000101')