Skip to content

Commit

Permalink
doc: echo watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
guofei9987 committed Dec 10, 2023
1 parent 595f303 commit dc3762b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,34 @@ hide_as_music.file_decode(filename='化物为音-解出来的文件.zip', wav_fi

```

## echo_watermark: 回声水印

```python
from hide_info.echo_watermark import EchoWatermark, get_error_rate
from hide_info import utils

ori_file = "sounds.wav" # 载体
embedded_file = "sounds_with_watermark.wav" # 嵌入水印后的文件名
wm_str = "回声水印算法,欢迎 star!" # 水印

wm_bits = utils.bytes2bin(wm_str.encode('utf-8'))
len_wm_bits = len(wm_bits)

# 嵌入水印
echo_wm = EchoWatermark(pwd=111001)
echo_wm.embed(origin_filename=ori_file, wm_bits=wm_bits, embed_filename=embedded_file)

# 提取水印
echo_wm = EchoWatermark(pwd=111001)
wm_extract = echo_wm.extract(embed_filename=embedded_file, len_wm_bits=len_wm_bits)

wm_str_extract = utils.bin2bytes(wm_extract).decode('utf-8', errors='replace')
print("解出水印:", wm_str_extract)
# 错误率:
get_error_rate(wm_extract, wm_bits)
```


## hide_in_text:藏物于文

功能:把一段信息(文件/文本/bytes),藏进一段文本中
Expand Down
8 changes: 4 additions & 4 deletions example/example_echo_watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from hide_info.echo_watermark import EchoWatermark, get_error_rate, get_snr
from hide_info import utils

ori_file = "sounds.wav"
embedded_file = "sounds_with_watermark.wav"
wm_str = "回声水印算法,欢迎 star!"
ori_file = "sounds.wav" # 载体
embedded_file = "sounds_with_watermark.wav" # 嵌入水印后的文件名
wm_str = "回声水印算法,欢迎 star!" # 水印

wm_bits = utils.bytes2bin(wm_str.encode('utf-8'))

len_wm_bits = len(wm_bits)

# embed:
Expand All @@ -20,6 +19,7 @@

wm_str_extract = utils.bin2bytes(wm_extract).decode('utf-8', errors='replace')
print("解出水印:", wm_str_extract)
# 错误率:
get_error_rate(wm_extract, wm_bits)

# %% There are 3 algorithms:
Expand Down

0 comments on commit dc3762b

Please sign in to comment.