Zero-width-lib is a library for manipulating zero width characters (ZWC), which are non-printing and invisible chars.
The common usage of ZWC includes fingerprinting confidential text, embedding hidden text and escaping from string matching (i.e. regex)...
The lib is inspired by this great medium article and got the following features:
- 💯stable & cover full test cases
- 😆support full width Unicode chars
- ⚡️dependencies & performance considered
- 📦support CJS, ESM and UMD
Forked from this JavaScript implementation.
WARNING: Not 100% compatible with original implementation.
pip install zero_width_lib
import zero_width_lib as zwlib
# or
from zero_width_lib import *
# note * represents the invisible ZWC
# U+ represents the Unicode for the character
# 0. six different zwc
my_dict = zwlib.zeroWidthDict
print(my_dict.zeroWidthSpace) # '*' U+200B
print(my_dict.zeroWidthNonJoiner) # '*' U+200C
print(my_dict.zeroWidthJoiner) # '*' U+200D
print(my_dict.leftToRightMark) # '*' U+200E
print(my_dict.rightToLeftMark) # '*' U+200F
print(my_dict.zeroWidthNoBreakSpace) # '*' U+FEFF
# 1. convert text
text = 'text'
zwc = zwlib.t2z(text) # '********'
back = zwlib.z2t(zwc) # 'text'
# 2. embed hidden text
visible = 'hello world'
hidden = 'transplanted by @shacha086'
encoded = zwlib.encode(visible, hidden) # 'h*********ello world'
decoded = zwlib.decode(encoded) # 'transplanted by @shacha086'
# 3. extract ZWC from text
extracted = zwlib.extract(encoded)
vis = extracted.vis # 'hello world'
hid = extracted.hid # '*********'
# 4. escape from string matching
forbidden = 'forbidden'
escaped = zwlib.split(forbidden) # 'f*o*r*b*i*d*d*e*n*'
MIT