Skip to main content

Zero-width-lib is a library for manipulating zero width characters (ZWC), which are non-printing and invisible chars.

Project description

zero-width-lib-python

What's zero-width-lib

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:

  1. 💯stable & cover full test cases
  2. 😆support full width Unicode chars
  3. ⚡️dependencies & performance considered
  4. 📦support CJS, ESM and UMD

Forked from this JavaScript implementation.

WARNING: Not 100% compatible with original implementation.

Install

pip install zero_width_lib

Usage

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*' 

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zero_width_lib-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file zero_width_lib-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zero_width_lib-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.6

File hashes

Hashes for zero_width_lib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13bb6c1d352b28844c9df739d5cf81301eec76c9f4fe44f9dccb11397529a4c5
MD5 93676daa9f34ad725ad5bc7e64d69eb3
BLAKE2b-256 228739688a826ed61c5c3040e07243ce1a029ab0b4b63438af5f9982d16c2375

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page