From 79879451fbc67da2e93024546cea11fa95e16c25 Mon Sep 17 00:00:00 2001 From: TianYuan Date: Mon, 31 Oct 2022 15:34:06 +0800 Subject: [PATCH] add watermark, test=doc (#2596) --- tools/watermark.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tools/watermark.py diff --git a/tools/watermark.py b/tools/watermark.py new file mode 100644 index 00000000..fc592d5b --- /dev/null +++ b/tools/watermark.py @@ -0,0 +1,20 @@ +# add watermark for text +def watermark(content, pattern): + m = list(zip(pattern * (len(content) // len(pattern) + 1), content)) + return ''.join([x for t in m + for x in t] + [pattern[len(content) % len(pattern)]]) + + +# remove cyclic watermark in text +def iwatermark(content): + e = [x for i, x in enumerate(content) if i % 2 == 0] + o = [x for i, x in enumerate(content) if i % 2 != 0] + for i in range(1, len(e) // 2 + 1): + if e[i:] == e[:-i]: + return ''.join(o) + return ''.join(e) + + +if __name__ == "__main__": + print(watermark('跟世龙对齐 Triton 开发计划', 'hbzs')) + print(iwatermark('h跟b世z龙s对h齐b zTsrhibtzosnh b开z发s计h划b'))