def stegano(): print(request.method) path = "cat.jpg" output_path = "catencodes.jpg" text = request.data Steganography.encode(path, output_path, text) return send_file(output_path, mimetype='image/jpeg')
def main(): path = "examples/apyr.jpg" path = os.path.abspath(path) s = Steganography(path) s.encode("Sample text") s.save("examples/apyr - encoded.jpg") print(s.decode("examples/apyr - encoded.png"))
def test_encode_and_decode_without_path_for_decoding(test_image, random_words): # ARRANGE for word in random_words: s = Steganography(test_image) # ACT s.encode(word) result = s.decode() # ASSERT assert result == word
def test_save_successful(test_image, tmp_folder): # ARRANGE s = Steganography(test_image) s.encode("doesnt matter") mock_png_path = os.path.join(tmp_folder, "save_sucess.png") s._path_as_png = MagicMock(return_value=mock_png_path) # ACT s.save(mock_png_path) # ASSERT assert os.path.exists(mock_png_path)
def test_encode_and_decode_with_path_for_decoding(tmp_folder, test_image, random_words): # ARRANGE for idx, word in enumerate(random_words): s = Steganography(test_image) # ACT s.encode(word) tmp_file = os.path.join(tmp_folder, f"image{idx}.jpg") s.save(tmp_file) result = s.decode(tmp_file.replace("jpg", "png")) # ASSERT assert result == word
def encode(): if 'show_image' not in request.files or 'hide_image' not in request.files: return redirect('/') show_image = request.files['show_image'] hide_image = request.files['hide_image'] if show_image.filename == '' or hide_image.filename == '': return redirect('/') if (show_image and allowed_file(show_image.filename)) and ( hide_image and allowed_file(hide_image.filename)): show_image_filename = secure_filename(show_image.filename) show_image_filename = filename_with_random_str(show_image_filename) show_image_path = os.path.join(app.config['UPLOAD_FOLDER'], show_image_filename) show_image.save(show_image_path) hide_image_filename = secure_filename(hide_image.filename) hide_image_filename = filename_with_random_str(hide_image_filename) hide_image_path = os.path.join(app.config['UPLOAD_FOLDER'], hide_image_filename) hide_image.save(hide_image_path) try: encoded_image = Steganography.encode(Image.open(show_image_path), Image.open(hide_image_path)) encoded_image_filename = 'encoded_' + show_image_filename encoded_image_path = os.path.join(app.config['UPLOAD_FOLDER'], encoded_image_filename) encoded_image.save(encoded_image_path) return render_template('main/encode.html', filename=encoded_image_filename) except ValueError as e: return str(e) else: return 'Not allowed extensions'
from steganography import Steganography, StegError if __name__ == '__main__': #ENCODE EXAMPLE try: steg = Steganography('monalisa.jpg') steg.encode("""I have no passwords or money to hide! -Just another poor programmer...""") except StegError: print('Insert a larger image or a smaller message!') #DECODE EXAMPLE # try: # filename = '' #puts here a encoded image # steg = Steganography(filename) # code = steg.decode() # print(code) # except StegError: # print('No one message was found!')
meta_data = PrettyMessage() meta_data_printer = threading.Thread(target=meta_data.message, args=("Encoding META-DATA...", Colors.INFO.value, 0.1, 15)) meta_data_printer.start() meta_data_printer.join() del meta_data, meta_data_printer text_data = PrettyMessage() text_data_printer = threading.Thread( target=text_data.message, args=("Encoding text in image...", Colors.INFO.value)) text_data_printer.start() stego.encode(text) text_data.need_run = False text_data_printer.join() del text_data, text_data_printer SystemMessages.complete('{} {} writed with success!'.format( len(text) - 1, 'character' if len(text) == 1 else 'characters')) elif choice == Operation.DECODE.value: try: text = stego.decode() except EncodeError: