mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-12 17:18:30 +02:00
added a shift parameter for the lsb module. closes #25
This commit is contained in:
parent
37aeb39167
commit
c3f6f392f3
2 changed files with 25 additions and 10 deletions
|
@ -20,9 +20,9 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
__author__ = "Cedric Bonhomme"
|
__author__ = "Cedric Bonhomme"
|
||||||
__version__ = "$Revision: 0.7 $"
|
__version__ = "$Revision: 0.8 $"
|
||||||
__date__ = "$Date: 2016/08/04 $"
|
__date__ = "$Date: 2016/08/04 $"
|
||||||
__revision__ = "$Date: 2017/05/16 $"
|
__revision__ = "$Date: 2019/06/01 $"
|
||||||
__license__ = "GPLv3"
|
__license__ = "GPLv3"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -58,6 +58,9 @@ group_secret.add_argument("-f", dest="secret_file",
|
||||||
parser_hide.add_argument("-o", "--output", dest="output_image_file",
|
parser_hide.add_argument("-o", "--output", dest="output_image_file",
|
||||||
required=True, help="Output image containing the secret.")
|
required=True, help="Output image containing the secret.")
|
||||||
|
|
||||||
|
# Shift the message to hide
|
||||||
|
parser_hide.add_argument("-s", "--shift", dest="shift", default=0,
|
||||||
|
help="Shift for the message to hide")
|
||||||
|
|
||||||
# Subparser: Reveal
|
# Subparser: Reveal
|
||||||
parser_reveal = subparsers.add_parser('reveal', help='reveal help')
|
parser_reveal = subparsers.add_parser('reveal', help='reveal help')
|
||||||
|
@ -69,7 +72,9 @@ parser_reveal.add_argument("-e", "--encoding", dest="encoding",
|
||||||
" UTF-8 (default) or UTF-32LE.")
|
" UTF-8 (default) or UTF-32LE.")
|
||||||
parser_reveal.add_argument("-o", dest="secret_binary",
|
parser_reveal.add_argument("-o", dest="secret_binary",
|
||||||
help="Output for the binary secret (Text or any binary file).")
|
help="Output for the binary secret (Text or any binary file).")
|
||||||
|
# Shift the message to reveal
|
||||||
|
parser_reveal.add_argument("-s", "--shift", dest="shift", default=0,
|
||||||
|
help="Shift for the reveal")
|
||||||
|
|
||||||
arguments = parser.parse_args()
|
arguments = parser.parse_args()
|
||||||
|
|
||||||
|
@ -81,7 +86,7 @@ if arguments.command == 'hide':
|
||||||
secret = tools.binary2base64(arguments.secret_file)
|
secret = tools.binary2base64(arguments.secret_file)
|
||||||
|
|
||||||
img_encoded = lsb.hide(arguments.input_image_file, secret,
|
img_encoded = lsb.hide(arguments.input_image_file, secret,
|
||||||
arguments.encoding)
|
arguments.encoding, int(arguments.shift))
|
||||||
try:
|
try:
|
||||||
img_encoded.save(arguments.output_image_file)
|
img_encoded.save(arguments.output_image_file)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -89,7 +94,8 @@ if arguments.command == 'hide':
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
elif arguments.command == 'reveal':
|
elif arguments.command == 'reveal':
|
||||||
secret = lsb.reveal(arguments.input_image_file, arguments.encoding)
|
secret = lsb.reveal(arguments.input_image_file, arguments.encoding,
|
||||||
|
int(arguments.shift))
|
||||||
if arguments.secret_binary != None:
|
if arguments.secret_binary != None:
|
||||||
data = tools.base642binary(secret)
|
data = tools.base642binary(secret)
|
||||||
with open(arguments.secret_binary, "wb") as f:
|
with open(arguments.secret_binary, "wb") as f:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Stéganô - Stéganô is a basic Python Steganography module.
|
# Stéganô - Stegano is a basic Python Steganography module.
|
||||||
# Copyright (C) 2010-2019 Cédric Bonhomme - https://www.cedricbonhomme.org
|
# Copyright (C) 2010-2019 Cédric Bonhomme - https://www.cedricbonhomme.org
|
||||||
#
|
#
|
||||||
# For more information : https://github.com/cedricbonhomme/Stegano
|
# For more information : https://github.com/cedricbonhomme/Stegano
|
||||||
|
@ -20,9 +20,9 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
__author__ = "Cedric Bonhomme"
|
__author__ = "Cedric Bonhomme"
|
||||||
__version__ = "$Revision: 0.3 $"
|
__version__ = "$Revision: 0.4 $"
|
||||||
__date__ = "$Date: 2016/08/04 $"
|
__date__ = "$Date: 2016/08/04 $"
|
||||||
__revision__ = "$Date: 2017/05/04 $"
|
__revision__ = "$Date: 2019/06/01 $"
|
||||||
__license__ = "GPLv3"
|
__license__ = "GPLv3"
|
||||||
|
|
||||||
from typing import IO, Union
|
from typing import IO, Union
|
||||||
|
@ -34,6 +34,7 @@ def hide(
|
||||||
input_image: Union[str, IO[bytes]],
|
input_image: Union[str, IO[bytes]],
|
||||||
message: str,
|
message: str,
|
||||||
encoding: str = "UTF-8",
|
encoding: str = "UTF-8",
|
||||||
|
shift: int = 0,
|
||||||
auto_convert_rgb: bool = False,
|
auto_convert_rgb: bool = False,
|
||||||
):
|
):
|
||||||
"""Hide a message (string) in an image with the
|
"""Hide a message (string) in an image with the
|
||||||
|
@ -72,6 +73,9 @@ def hide(
|
||||||
)
|
)
|
||||||
for row in range(height):
|
for row in range(height):
|
||||||
for col in range(width):
|
for col in range(width):
|
||||||
|
if shift != 0:
|
||||||
|
shift -= 1
|
||||||
|
continue
|
||||||
if index + 3 <= len_message_bits:
|
if index + 3 <= len_message_bits:
|
||||||
|
|
||||||
# Get the colour component.
|
# Get the colour component.
|
||||||
|
@ -97,7 +101,10 @@ def hide(
|
||||||
return encoded
|
return encoded
|
||||||
|
|
||||||
|
|
||||||
def reveal(input_image: Union[str, IO[bytes]], encoding="UTF-8"):
|
def reveal(input_image: Union[str, IO[bytes]],
|
||||||
|
encoding: str = "UTF-8",
|
||||||
|
shift: int = 0
|
||||||
|
):
|
||||||
"""Find a message in an image (with the LSB technique).
|
"""Find a message in an image (with the LSB technique).
|
||||||
"""
|
"""
|
||||||
img = tools.open_image(input_image)
|
img = tools.open_image(input_image)
|
||||||
|
@ -107,7 +114,9 @@ def reveal(input_image: Union[str, IO[bytes]], encoding="UTF-8"):
|
||||||
limit = None
|
limit = None
|
||||||
for row in range(height):
|
for row in range(height):
|
||||||
for col in range(width):
|
for col in range(width):
|
||||||
|
if shift != 0:
|
||||||
|
shift -= 1
|
||||||
|
continue
|
||||||
# pixel = [r, g, b] or [r,g,b,a]
|
# pixel = [r, g, b] or [r,g,b,a]
|
||||||
pixel = img.getpixel((col, row))
|
pixel = img.getpixel((col, row))
|
||||||
if img.mode == "RGBA":
|
if img.mode == "RGBA":
|
||||||
|
|
Loading…
Add table
Reference in a new issue