YassineYousfi
commited on
Commit
·
6aea31a
1
Parent(s):
06242ba
V0 WIP
Browse files- app.py +35 -4
- example.py +0 -36
- requirements.txt +1 -0
- stc.py +6 -7
app.py
CHANGED
|
@@ -1,7 +1,38 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
def HILL(input_image, operation, message, key):
|
| 11 |
+
input_image.seek(0)
|
| 12 |
+
buffer = input_image.read()
|
| 13 |
+
I = cv2.imdecode(np.frombuffer(buffer, np.uint8), 1)
|
| 14 |
+
I = cv2.cvtColor(I,cv2.COLOR_BGR2GRAY)
|
| 15 |
+
cv2.imwrite('tmp/file.png',I)
|
| 16 |
+
|
| 17 |
+
if operation == 'decode':
|
| 18 |
+
stc.extract('tmp/file.png', key, 'tmp/output.txt')
|
| 19 |
+
return 'tmp/output.txt'
|
| 20 |
+
|
| 21 |
+
else:
|
| 22 |
+
H = np.array(
|
| 23 |
+
[[-1, 2, -1],
|
| 24 |
+
[ 2, -4, 2],
|
| 25 |
+
[-1, 2, -1]])
|
| 26 |
+
L1 = np.ones((3, 3)).astype('float32')/(3**2)
|
| 27 |
+
L2 = np.ones((15, 15)).astype('float32')/(15**2)
|
| 28 |
+
costs = signal.convolve2d(I, H, mode='same')
|
| 29 |
+
costs = abs(costs)
|
| 30 |
+
costs = signal.convolve2d(costs, L1, mode='same')
|
| 31 |
+
costs = 1/costs
|
| 32 |
+
costs = signal.convolve2d(costs, L2, mode='same')
|
| 33 |
+
costs[costs == np.inf] = 1
|
| 34 |
+
stc.embed('tmp/file.png', costs, message, key, 'tmp/stego.png')
|
| 35 |
+
return 'tmp/stego.png'
|
| 36 |
+
|
| 37 |
+
iface = gr.Interface(HILL, ["file", gr.inputs.Radio(["encode", "decode"]), "text", "text"], "file")
|
| 38 |
+
iface.launch(share=False)
|
example.py
DELETED
|
@@ -1,36 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
|
| 3 |
-
import stc
|
| 4 |
-
import numpy as np
|
| 5 |
-
import imageio
|
| 6 |
-
from scipy import signal
|
| 7 |
-
|
| 8 |
-
input_image = 'files/1.pgm'
|
| 9 |
-
|
| 10 |
-
def HILL(input_image):
|
| 11 |
-
H = np.array(
|
| 12 |
-
[[-1, 2, -1],
|
| 13 |
-
[ 2, -4, 2],
|
| 14 |
-
[-1, 2, -1]])
|
| 15 |
-
L1 = np.ones((3, 3)).astype('float32')/(3**2)
|
| 16 |
-
L2 = np.ones((15, 15)).astype('float32')/(15**2)
|
| 17 |
-
I = imageio.imread(input_image)
|
| 18 |
-
costs = signal.convolve2d(I, H, mode='same')
|
| 19 |
-
costs = abs(costs)
|
| 20 |
-
costs = signal.convolve2d(costs, L1, mode='same')
|
| 21 |
-
costs = 1/costs
|
| 22 |
-
costs = signal.convolve2d(costs, L2, mode='same')
|
| 23 |
-
costs[costs == np.inf] = 1
|
| 24 |
-
return costs
|
| 25 |
-
|
| 26 |
-
costs = HILL(input_image)
|
| 27 |
-
print(costs)
|
| 28 |
-
|
| 29 |
-
stc.embed(input_image, costs, 'files/message.txt', 's3cr3t', 'files/stego.png')
|
| 30 |
-
stc.extract('files/stego.png', 's3cr3t', 'files/output.txt')
|
| 31 |
-
|
| 32 |
-
print(open('files/output.txt', 'r').read())
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
pycryptodome
|
|
|
|
|
|
| 1 |
pycryptodome
|
| 2 |
+
imageio
|
stc.py
CHANGED
|
@@ -12,10 +12,9 @@ from Crypto.Cipher import AES
|
|
| 12 |
from Crypto.Random import get_random_bytes
|
| 13 |
from Crypto.Util.Padding import pad, unpad
|
| 14 |
|
| 15 |
-
def prepare_message(
|
| 16 |
|
| 17 |
-
|
| 18 |
-
content_data = f.read().encode('utf-8')
|
| 19 |
|
| 20 |
# Prepare a header with basic data about the message
|
| 21 |
content_ver=struct.pack("B", 1) # version 1
|
|
@@ -101,15 +100,15 @@ def embed(input_img_path, cost_matrix, msg_file_path, password, output_img_path
|
|
| 101 |
if cover[idx]==0:
|
| 102 |
costs[3*idx+0] = INF
|
| 103 |
costs[3*idx+1] = 0
|
| 104 |
-
costs[3*idx+2] = cost_matrix[
|
| 105 |
elif cover[idx]==255:
|
| 106 |
-
costs[3*idx+0] = cost_matrix[
|
| 107 |
costs[3*idx+1] = 0
|
| 108 |
costs[3*idx+2] = INF
|
| 109 |
else:
|
| 110 |
-
costs[3*idx+0] = cost_matrix[
|
| 111 |
costs[3*idx+1] = 0
|
| 112 |
-
costs[3*idx+2] = cost_matrix[
|
| 113 |
idx += 1
|
| 114 |
|
| 115 |
# Prepare message
|
|
|
|
| 12 |
from Crypto.Random import get_random_bytes
|
| 13 |
from Crypto.Util.Padding import pad, unpad
|
| 14 |
|
| 15 |
+
def prepare_message(text, password):
|
| 16 |
|
| 17 |
+
content_data = text.encode('utf-8')
|
|
|
|
| 18 |
|
| 19 |
# Prepare a header with basic data about the message
|
| 20 |
content_ver=struct.pack("B", 1) # version 1
|
|
|
|
| 100 |
if cover[idx]==0:
|
| 101 |
costs[3*idx+0] = INF
|
| 102 |
costs[3*idx+1] = 0
|
| 103 |
+
costs[3*idx+2] = cost_matrix[j, i]
|
| 104 |
elif cover[idx]==255:
|
| 105 |
+
costs[3*idx+0] = cost_matrix[j, i]
|
| 106 |
costs[3*idx+1] = 0
|
| 107 |
costs[3*idx+2] = INF
|
| 108 |
else:
|
| 109 |
+
costs[3*idx+0] = cost_matrix[j, i]
|
| 110 |
costs[3*idx+1] = 0
|
| 111 |
+
costs[3*idx+2] = cost_matrix[j, i]
|
| 112 |
idx += 1
|
| 113 |
|
| 114 |
# Prepare message
|