-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
84 lines (67 loc) · 2.32 KB
/
main.py
File metadata and controls
84 lines (67 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import sys
sys.path.insert(0, './src')
import streamlit as st
from PIL import Image
from src.lsb_stegno import lsb_encode, lsb_decode
from src.n_share import generate_shares, compress_shares
menu = st.sidebar.radio('Options', ['Docs', 'Encode', 'Decode'])
if menu == 'Docs':
st.title('Documentation')
with open('README.md', 'r') as f:
docs = f.read()
st.markdown(docs, unsafe_allow_html=True)
elif menu == 'Encode':
st.title('Encoding')
# Image
img = st.file_uploader('Upload image file', type=['jpg', 'png', 'jpeg'])
if img is not None:
img = Image.open(img)
try:
img.save('images/img.jpg')
except:
img.save('images/img.png')
st.image(img, caption='Selected image to use for data encoding',
use_column_width=True)
# Data
txt = st.text_input('Message to hide')
# Encode message
if st.button('Encode data and Generate shares'):
# Checks
if len(txt) == 0:
st.warning('No data to hide')
elif img is None:
st.warning('No image file selected')
# Generate splits
else:
generate_shares(lsb_encode(txt))
try:
os.remove('images/img.jpg')
except FileNotFoundError:
os.remove('images/img.png')
st.success('Data encoded, Shares generated in folder [images]')
elif menu == 'Decode':
st.title('Decoding')
# Share 1
img1 = st.file_uploader('Upload Share 1', type=['png'])
if img1 is not None:
img1 = Image.open(img1)
img1.save('images/share1.png')
st.image(img1, caption='Share 1', use_column_width=True)
# Share 2
img2 = st.file_uploader('Upload Share 2', type=['png'])
if img2 is not None:
img2 = Image.open(img2)
img2.save('images/share2.png')
st.image(img2, caption='Share 2', use_column_width=True)
# Decode message
if st.button('Compress shares and Decode message'):
# Check
if img1 is None or img2 is None:
st.warning('Upload both shares')
# Compress shares
else:
compress_shares()
os.remove('images/share1.png')
os.remove('images/share2.png')
st.success('Decoded message: ' + lsb_decode('images/compress.png'))