-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder.py
29 lines (22 loc) · 1.12 KB
/
encoder.py
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
# This a demo file showing how the stega.py package can be used, it is not a part of the said package
#
#
import stega
def encode():
#Open the message file and convert it to binary
message = stega.Message.fromimagefile("example/lennalight.png", c1=0, c2=3) #c1 - c2 represents the range of color channels (e.g. 0-3 means that all the RGB channels will be included)
binary = message.to_binary()
#Open the host image and inject binary into it, then save the modified image file
host = stega.Host.fromimagefile("example/lenna.png")
host.inject_binary(binary, c2=3)
host.save("images_encoded/")
def decode():
#Open the modified host file and extract binary from it
host = stega.Host.fromimagefile("images_encoded/host_encoded.png")
binary = host.extract_binary(c2=3)
#Create a message class from the extracted binary and convert it back to the original message, then save the decoded file
message = stega.Message.frombinary(binary)
message.decode(all=True) #if all = True, decode all the data from the host, even if it repeats
message.save("messages_decoded/")
encode()
decode()