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 destegano(): files= request.files['image'] secret_text = Steganography.decode(files) #print(files, file=sys.stderr) return secret_text # path = "cat.jpg" # output_path = "catencode.jpg" # text = 'The quick brown fox jumps over the lazy dog.' # Steganography.encode(path, output_path, text) # secret_text = Steganography.decode(output_path) # print(secret_text)
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 decode(): if request.method == 'POST': if 'image' not in request.files: return redirect(request.url) image = request.files['image'] if image.filename == '': return redirect(request.url) if image and allowed_file(image.filename): image_filename = secure_filename(image.filename) image_filename = filename_with_random_str(image_filename) image_path = os.path.join(app.config['UPLOAD_FOLDER'], image_filename) image.save(image_path) decoded_image = Steganography.decode(Image.open(image_path)) decoded_image_filename = 'decoded_' + image_filename decoded_image_path = os.path.join(app.config['UPLOAD_FOLDER'], decoded_image_filename) decoded_image.save(decoded_image_path) return render_template('decode/show.html', filename=decoded_image_filename) return render_template('decode/index.html')
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: SystemMessages.error("You can't decode an image not encoded!") os.system(clear_com) SystemMessages.banner(term_width) meta_data = PrettyMessage() meta_data_printer = threading.Thread(target=meta_data.message, args=("Decoding META-DATA...", Colors.INFO.value, 0.1, 20)) meta_data_printer.start() meta_data_printer.join() del meta_data, meta_data_printer