-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconceal.py
executable file
·66 lines (49 loc) · 2.37 KB
/
conceal.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
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
#!/usr/bin/python
import argparse
import mimetypes
import logging
from conceal.image import Image
from conceal.stego import Stego
logging.basicConfig(level=logging.CRITICAL)
logger = logging.getLogger()
def main():
"""
Main
:return:
"""
# setup class instantiation
carrier = Image(args.input)
# read the carrier image into memory
carrier.read()
conceal = Stego(carrier)
# do the encode function if the operation specified was to encode
if args.operation == "encode":
# read in the secret file
file = open(args.file, "rb").read()
conceal.hide_file = file
# determine the file type used for the secret file
mime = mimetypes.guess_type(args.file)
# encode the secret file into the carrier file, encrypted with a password if specified
carrier = conceal.encode(encrypt=args.password or False, mime=mime)
carrier.write(args.output)
# do the decode function if the operation specified was to decode
elif args.operation == "decode":
# determine the file type used for the secret file
mime = mimetypes.guess_type(args.output)
# decode the carrier file to reveal the secret file, with a password if secret file is encrypted
raw = conceal.decode(decrypt=args.password or False, mime=mime)
# write out to specified output file location
with open(args.output, "wb") as f:
f.write(raw)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='A steganography tool to conceal a file within an image.')
parser.add_argument('-i', '--input', dest='input', help='The carrier image to hold the concealed data')
parser.add_argument('-o', '--output', dest='output', help='The filename to output the combined files as')
parser.add_argument('-f', '--file', dest='file', help='The file to store in the carrier image')
parser.add_argument('-p', '--password', dest='password', action="store", help='Encrypt the embedded file with a password')
parser.add_argument('-v', '--verbose', dest='verbose', action='count', default=0, help='Increase verbosity level')
parser.add_argument('operation', choices=['encode', 'decode'], help="Supply the operation you want to perform on the image")
args = parser.parse_args()
if args.verbose:
logger.setLevel(logging.CRITICAL - (10 * int(args.verbose)))
main()