Skip to content

Commit c2cb6ce

Browse files
committed
Image Steganography Added
1 parent 381eab1 commit c2cb6ce

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

Image Steganography/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Image Steganography
2+
The python script can encode a message in an image(s) and also decode the text from the image(s)
3+
4+
What the program does?
5+
- Can take multiple images at the same time
6+
- Encode the text into the image(s)
7+
- Decode the text from the image(s)
8+
9+
10+
### Requirements
11+
Python3.6+
12+
> pip install -r requirements.txt
13+
14+
15+
### Usage
16+
```
17+
image.py [-h] -f FILES [FILES ...] [-e ENCODE] [-d]
18+
19+
STEGANOGRAPHY IN IMAGES
20+
21+
optional arguments:
22+
-h, --help show this help message and exit
23+
-f FILES [FILES ...] Image File
24+
-e ENCODE Encode The Text In Image
25+
-d Decode The Text In Image
26+
27+
```
28+
29+
### Contribution
30+
31+
Any kind of contributions are welcome.
32+
33+
1. Fork the project
34+
2. Commit your changes
35+
3. Open a pull request
36+
37+

Image Steganography/image.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import argparse
2+
import os
3+
4+
from PIL import Image
5+
import stepic
6+
7+
8+
def encode(file, text):
9+
# Open Image or file in which you want to hide your data
10+
image = Image.open(file)
11+
12+
# Convert the string to bytes
13+
text = bytes(text, 'utf-8')
14+
15+
# Encode some text into your image file and save it in another file
16+
encodeImage = stepic.encode(image, text)
17+
18+
# Get the filename from the path
19+
filename = os.path.splitext(os.path.basename(file))[0]
20+
21+
# Save the image in PNG file
22+
encodeImage.save(f'{filename}_enc.png', 'PNG')
23+
24+
print(f'File Encoded: {filename}_enc.png')
25+
print(f'String Used To Encode: {text}')
26+
27+
28+
def decode(path):
29+
# Open Image or file in which data exists
30+
image = Image.open(path)
31+
32+
# Decode the image to extract the text
33+
decodeImage = stepic.decode(image)
34+
35+
# Print the text
36+
print(f'Decoded String From Image: {decodeImage}')
37+
38+
39+
def main():
40+
parser = argparse.ArgumentParser(description='STEGANOGRAPHY IN IMAGES')
41+
42+
# Argument is for images to encode/decode
43+
parser.add_argument('-f', dest='files', nargs='+', type=str, help='Image File', required=True)
44+
45+
# Argument is to encode in the image
46+
parser.add_argument('-e', dest='encode', type=str, help='Encode The Text In Image')
47+
48+
# Argument is to decode from image
49+
parser.add_argument('-d', dest='decode', action='store_true', help='Decode The Text In Image')
50+
51+
args = parser.parse_args()
52+
53+
# Get the files
54+
files = args.files
55+
56+
if files:
57+
# If user wants to encode
58+
if args.encode:
59+
# Iterate through the files
60+
for file in files:
61+
# Check if the file exists
62+
if os.path.isfile(file):
63+
# Call the function
64+
encode(file, args.encode)
65+
66+
else:
67+
68+
print(f'File Not Found: {file}')
69+
70+
# If user wants to decode
71+
elif args.decode:
72+
# Iterate through the files
73+
for file in files:
74+
# Check if the file exists
75+
if os.path.isfile(file):
76+
# Call the function
77+
decode(file)
78+
79+
else:
80+
print(f'File Not Found: {file}')
81+
82+
else:
83+
print('Use -h For Help')
84+
85+
else:
86+
print('File Not Found')
87+
88+
89+
if __name__ == '__main__':
90+
main()

Image Steganography/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Pillow==8.1.0
2+
stepic==0.5.0

0 commit comments

Comments
 (0)