YassineYousfi
commited on
Commit
·
3fb4dd7
1
Parent(s):
9649f08
randomize names
Browse files
app.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import stc
|
| 3 |
-
import numpy as np
|
| 4 |
-
import imageio
|
| 5 |
-
from scipy import signal
|
| 6 |
import cv2
|
|
|
|
|
|
|
|
|
|
| 7 |
from PIL import Image
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
title = "Steganography"
|
|
@@ -13,22 +13,23 @@ description = '''Explore hiding messages in images using content adaptive stega
|
|
| 13 |
We use HILL https://ieeexplore.ieee.org/document/7025854 .
|
| 14 |
Python implementation adapted from Daniel Lerch's https://github.com/daniellerch/pySTC .
|
| 15 |
To encode:
|
| 16 |
-
Drag and drop a PNG file, write a message and enter a key (remember the key).
|
| 17 |
To decode:
|
| 18 |
-
|
| 19 |
-
Note that this software is supplied "as is," without any services or guaranties.
|
| 20 |
'''
|
| 21 |
|
| 22 |
def HILL(input_image, operation, message, key):
|
|
|
|
| 23 |
input_image.seek(0)
|
| 24 |
buffer = input_image.read()
|
| 25 |
I = cv2.imdecode(np.frombuffer(buffer, np.uint8), 1)
|
| 26 |
I = cv2.cvtColor(I,cv2.COLOR_BGR2GRAY)
|
| 27 |
-
cv2.imwrite('tmp/
|
| 28 |
|
| 29 |
if operation == 'decode':
|
| 30 |
-
stc.extract('tmp/
|
| 31 |
-
return 'tmp/
|
| 32 |
|
| 33 |
else:
|
| 34 |
H = np.array(
|
|
@@ -43,8 +44,8 @@ def HILL(input_image, operation, message, key):
|
|
| 43 |
costs = 1/costs
|
| 44 |
costs = signal.convolve2d(costs, L2, mode='same', boundary='symm')
|
| 45 |
costs[costs == np.inf] = 1
|
| 46 |
-
stc.embed('tmp/
|
| 47 |
-
return 'tmp/
|
| 48 |
|
| 49 |
iface = gr.Interface(HILL,
|
| 50 |
['file', gr.inputs.Radio(['encode', 'decode']), 'text', 'text'],
|
|
|
|
|
|
|
| 1 |
import stc
|
|
|
|
|
|
|
|
|
|
| 2 |
import cv2
|
| 3 |
+
import random
|
| 4 |
+
import numpy as np
|
| 5 |
+
import gradio as gr
|
| 6 |
from PIL import Image
|
| 7 |
+
from scipy import signal
|
| 8 |
|
| 9 |
|
| 10 |
title = "Steganography"
|
|
|
|
| 13 |
We use HILL https://ieeexplore.ieee.org/document/7025854 .
|
| 14 |
Python implementation adapted from Daniel Lerch's https://github.com/daniellerch/pySTC .
|
| 15 |
To encode:
|
| 16 |
+
Drag and drop a PNG file, write a message and enter a key (remember the key), the generated image has the secret message encoded.
|
| 17 |
To decode:
|
| 18 |
+
Drag and drop the stego file that you just generated, enter the key.
|
| 19 |
+
Note that this software is supplied "as is," without any services or security guaranties.
|
| 20 |
'''
|
| 21 |
|
| 22 |
def HILL(input_image, operation, message, key):
|
| 23 |
+
tmp_name = str(random.randint(100,1000))
|
| 24 |
input_image.seek(0)
|
| 25 |
buffer = input_image.read()
|
| 26 |
I = cv2.imdecode(np.frombuffer(buffer, np.uint8), 1)
|
| 27 |
I = cv2.cvtColor(I,cv2.COLOR_BGR2GRAY)
|
| 28 |
+
cv2.imwrite('tmp/'+tmp_name+'.png',I)
|
| 29 |
|
| 30 |
if operation == 'decode':
|
| 31 |
+
stc.extract('tmp/'+tmp_name+'.png', key, 'tmp/'+tmp_name+'.txt')
|
| 32 |
+
return 'tmp/'+tmp_name+'.txt'
|
| 33 |
|
| 34 |
else:
|
| 35 |
H = np.array(
|
|
|
|
| 44 |
costs = 1/costs
|
| 45 |
costs = signal.convolve2d(costs, L2, mode='same', boundary='symm')
|
| 46 |
costs[costs == np.inf] = 1
|
| 47 |
+
stc.embed('tmp/'+tmp_name+'.png', costs, message, key, 'tmp/'+tmp_name+'.png')
|
| 48 |
+
return 'tmp/'+tmp_name+'.png'
|
| 49 |
|
| 50 |
iface = gr.Interface(HILL,
|
| 51 |
['file', gr.inputs.Radio(['encode', 'decode']), 'text', 'text'],
|
stc.py
CHANGED
|
@@ -122,6 +122,7 @@ def embed(input_img_path, cost_matrix, msg_file_path, password, output_img_path
|
|
| 122 |
if i<len(msg_bits):
|
| 123 |
message[i] = msg_bits[i]
|
| 124 |
else:
|
|
|
|
| 125 |
message[i] = 0
|
| 126 |
# Hide message
|
| 127 |
stego = (c_int*(width*height))()
|
|
|
|
| 122 |
if i<len(msg_bits):
|
| 123 |
message[i] = msg_bits[i]
|
| 124 |
else:
|
| 125 |
+
# This doesn't look optimal
|
| 126 |
message[i] = 0
|
| 127 |
# Hide message
|
| 128 |
stego = (c_int*(width*height))()
|