mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-06-27 19:06:12 +02:00
chg: [style] Reformat with black.
This commit is contained in:
parent
6fd80429a4
commit
e8ed79ae9e
1 changed files with 14 additions and 7 deletions
|
@ -25,13 +25,15 @@ __license__ = "GPLv3"
|
|||
|
||||
import wave
|
||||
from typing import IO, Union
|
||||
|
||||
from stegano import tools
|
||||
|
||||
|
||||
def hide(
|
||||
input_file: Union[str, IO[bytes]],
|
||||
message: str,
|
||||
output_file: Union[str, IO[bytes]],
|
||||
encoding: str = "UTF-8"
|
||||
encoding: str = "UTF-8",
|
||||
):
|
||||
"""
|
||||
Hide a message (string) in a .wav audio file.
|
||||
|
@ -51,7 +53,9 @@ def hide(
|
|||
|
||||
nsamples = nframes * nchannels
|
||||
|
||||
message_bits = f"{message_length:08b}" + "".join(tools.a2bits_list(message, encoding))
|
||||
message_bits = f"{message_length:08b}" + "".join(
|
||||
tools.a2bits_list(message, encoding)
|
||||
)
|
||||
assert len(message_bits) <= nsamples, "message is too long"
|
||||
|
||||
# copy over .wav params to output
|
||||
|
@ -100,6 +104,9 @@ def reveal(input_file: Union[str, IO[bytes]], encoding: str = "UTF-8"):
|
|||
message_bits += str(frames[i] & 1)
|
||||
|
||||
# Convert bits to string
|
||||
chars = [chr(int(message_bits[i:i+encoding_len], 2)) for i in range(0, len(message_bits), encoding_len)]
|
||||
chars = [
|
||||
chr(int(message_bits[i : i + encoding_len], 2))
|
||||
for i in range(0, len(message_bits), encoding_len)
|
||||
]
|
||||
message = "".join(chars)
|
||||
return message
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue