text_blind_watermark
在文本中嵌入信息(盲水印),使信息不可见,且文本的变化不易察觉。
- 视频演示:https://www.bilibili.com/video/BV1m3411s7kT
- 在线演示(旧版本,仅供演示):https://www.guofei.site/pictures_for_blog/app/text_watermark/v1.html
- 中文说明 README_cn.md
- 源代码: https://github.com/guofei9987/text_blind_watermark
- Rust版本: https://github.com/guofei9987/text-blind-watermark
可用于:
- 微信
- 钉钉
- 知乎
- ...
使用方法
安装
>pip install text_blind_watermark
在文本中嵌入信息:
from text_blind_watermark import TextBlindWatermark2
password = '20190808'
text = '这句话中有盲水印,你能提取出来吗?'
watermark = 'github.com/guofei9987'
text_blind_wm = TextBlindWatermark2(password=password)
text_with_wm = text_blind_wm.embed(text=text, watermark=watermark)
print(text_with_wm)
从文本中提取信息
text_blind_wm2 = TextBlindWatermark2(password=password)
wm_extract = text_blind_wm2.extract(text_with_wm)
print('提取内容:', wm_extract)
github.com/guofei9987
chr_type
你可以选择不同的类型以获得更好的性能。
from text_blind_watermark import TextBlindWatermark2
password = '20190808'
text = '这句话中有盲水印,你能提取出来吗?'
watermark = 'github.com/guofei9987'
text_blind_wm = TextBlindWatermark2(password=password, chr_type=(3, 4))
text_with_wm = text_blind_wm.embed(text=text, watermark=watermark)
print(text_with_wm)
text_blind_wm2 = TextBlindWatermark2(password=password, chr_type=(3, 4))
wm_extract = text_blind_wm2.extract(text_with_wm)
print('提取内容:', wm_extract)
assert watermark == wm_extract
另一种更稳健的算法
Alice在文本中嵌入她的文本水印:
from text_blind_watermark import TextBlindWatermark
watermark = "绝密:两点老地方见!"
text = "这句话中有盲水印,你能提取出来吗?" * 16
password = "20190808"
twm = TextBlindWatermark(password=password)
twm.read_wm(watermark=watermark)
twm.read_text(text=text)
text_embed = twm.embed()
print("打上盲水印之后:")
print(text_embed)
然后,你可以将这段文本粘贴到需要的地方。
Bob提取不可见的水印
from text_blind_watermark import TextBlindWatermark
password = "20190808"
twm_new = TextBlindWatermark(password=password)
wm_extract = twm_new.extract(text_embed)
print("解出的盲水印:")
print(wm_extract)