$ pip install textwatermark
$ textwatermark -v insert -f './tests/text/number.txt' -m ALPHA_NUMERICAL -t HOMOGRAPH_NUMBERS -x 999 -w 123
Ӏ2𝟑𝟒𝟓Ⳓ𝟟890
保存水印参数:
$ textwatermark -v insert -f './tests/text/number.txt' -m ALPHA_NUMERICAL -t HOMOGRAPH_NUMBERS -x 999 -w 123 -e
{"tpl_type": "HOMOGRAPH_NUMBERS", "confusables_chars": [], "confusables_chars_key": "", "wm_base": 7, "method": 1, "wm_mode": 5, "wm_len": 7, "wm_loop": false, "start_at": 0, "version": "0.1.2"}
从文本提取水印:
$ textwatermark -v retrieve -f out.txt -p '{"tpl_type": "HOMOGRAPH_NUMBERS", "confusables_chars": [], "confusables_chars_key": "", "wm_base": 7, "method": 1, "wm_mode": 5, "wm_len": 7, "wm_loop": false, "start_at": 0, "version": "0.1.2"}'
The retrieved watermark is: 123
代码调用:
'''Sample Example'''
import os
from textwatermark.defines import WMMode
from textwatermark.main import TextWatermark
from textwatermark.template_type import WMTemplateType
# 1.Init TextWatermark instance
wm_mode = WMMode.REAL_NUMBER
wm = TextWatermark(wm_mode=wm_mode)
# 2.Choose a watermark template
wm.set_tpl_type(tpl_type=WMTemplateType.HOMOGRAPH_NUMBERS)
# 3.Set the maximum value of the watermark string
wm_max = '9'*9
wm.set_wm_max(wm_max=wm_max)
# 4.Set the text to be watermarked
wm.set_text_file(path=os.path.abspath('../tests/text/1.txt'))
# 5.Insert watermark string to text
wm_str = '123456789'
wm_text = wm.insert_watermark(wm_str=wm_str)
print(wm_text)
##############################################################
# Save the parameters to retrieve the watermark
params = wm.export_params()
# retrieve the watermark
wm_out_str = TextWatermark.retrieve_watermark(wm_text=wm_text, params=params)
assert wm_out_str == wm_str
更多参见:https://textwatermark.jd.army/usage/
找回水印
$ textwatermark -v retrieve -b 10010000011000100000101000110000111 -p '{"tpl_type": "FONT_COLOR", "confusables_chars": [], "confusables_chars_key": "black4", "wm_base": 2, "method": 3, "wm_mode": 5, "wm_len": 35, "wm_loop": false, "start_at": 0, "version": "0.1.2"}'
The retrieved watermark is: 123456
DBIR 2022:https://www.verizon.com/business/resources/T27b/reports/dbir/2022-data-breach-investigations-report-dbir.pdf#pdfjs.action=download