def decode_msg_from_bit(img_array, stegobit): img_bit_array = util.unpack_img_to_bits(img_array) bitmsg = [byte[stegobit] for byte in img_bit_array] msg = np.packbits(bitmsg) return''.join(chr(x) for x in msg if x != 0)
def decode_msg_from_bit(img_array, stegobit): img_bit_array = util.unpack_img_to_bits(img_array) bitmsg = [byte[stegobit] for byte in img_bit_array] msg = np.packbits(bitmsg) return ''.join(chr(x) for x in msg if x != 0)
def encode_msg_in_bit(img_array, msg, stegobit): assert len(msg) * 8 < img_array.size, 'The message is too long for this image.' binmsg = np.array(convert_msg_to_bin(msg), dtype= np.uint8) zeros = np.zeros(img_array.size - binmsg.size, dtype=np.uint8) padmsg = np.append(binmsg, zeros) img_bit_array = util.unpack_img_to_bits(img_array.astype(np.uint8)) #manipulation for byte, msg_bit in zip(img_bit_array, padmsg): byte[stegobit] = msg_bit return util.pack_bits_to_img(img_bit_array, img_array)
def encode_msg_in_bit(img_array, msg, stegobit): assert len( msg) * 8 < img_array.size, 'The message is too long for this image.' binmsg = np.array(convert_msg_to_bin(msg), dtype=np.uint8) zeros = np.zeros(img_array.size - binmsg.size, dtype=np.uint8) padmsg = np.append(binmsg, zeros) img_bit_array = util.unpack_img_to_bits(img_array.astype(np.uint8)) #manipulation for byte, msg_bit in zip(img_bit_array, padmsg): byte[stegobit] = msg_bit return util.pack_bits_to_img(img_bit_array, img_array)