Skip to main content

Text Obfuscator

Obfuscate your message with Text Obfuscator

CI PyPI Python 3.8.7 codecov

Installation

pip install -U textobfuscator

Usage

import random
from textobfuscator.obfuscator import TextObfuscator

# 1. Replace char.
# First, now we define rules: replace chars groups.
CHARS_GROUPS_SOURCE_MAP = (
  ["😯", "🤣"],
  ["❌", "✅"],
)

# 2. Format(Optional)
# Second, let's make some rules to fill the vars that we inserted.
FORMAT_PREFIX_RULES = {
  "fake_name": lambda: random.choice(("John", "Min", "William")),
  "random_weather": lambda: random.choice(("cloudy", "rainy", "sunny", "windy"))
}

obfuscator = TextObfuscator(
   replace_source_map=CHARS_GROUPS_SOURCE_MAP,
   format_prefix_rules=FORMAT_PREFIX_RULES,
)

Now we have an instance of TextObfuscator: obfuscator, let's do some obfuscations.

from textobfuscator.processor import BreakWord, ObfuscationConfig, Replace

# For each obfuscation, we may specify different rules, such as controls for different words or the number of substitutions, so we make rule here first.
BREAK_WORDS_RULES = [
   # We break the word `hello` twice, and put `*` into the middle, like `h*el*lo`
   BreakWord(word="hello", places=2, fill="*"),
   # We break the word `world` once, and put `-` into the middle, like `wor-ld`
   BreakWord(word="world", places=1, fill="-"),
]
OBFUSCATOR_CONFIG = ObfuscationConfig(
   # During the entire obfuscation process, we only replace 1 times.
   replaces=Replace(count=1),
   break_words=BREAK_WORDS_RULES,
)

# OK, let's do the obfuscation.

>>> original1 = "hello world!"
>>> obfuscated = obfuscator.obfuscate(original1, config=OBFUSCATOR_CONFIG)
>>> print(obfuscated)
>>> h*ell*o wor-ld!

>>> original2 = "❌ hi {fake_name}, today's weather is {random_weather} 😯"

>>> obfuscated = obfuscator.obfuscate(original2, config=OBFUSCATOR_CONFIG)
>>> print(obfuscated)
>>> ❌ hi John, today's weather is windy 🤣

# Once more.
>>> obfuscated = obfuscator.obfuscate(original2, config=OBFUSCATOR_CONFIG)
>>> print(obfuscated)
>>> ✅ hi Min, today's weather is sunny 😯

Obfuscation Detail

  1. Split content into segments by every args position.
  2. Break words.
    1. Break words on each segment.
    2. Merge all segments and put back all key args in places.
  3. Replace.
    1. Temporarily remove all key args.
    2. Replace matching chars according to the given mapping table and config.
    3. Put back all key args that removed on above in places.
  4. Format.
    1. Merge the pre-defined key args and given key args. Here pre-defined args means we can create custom var generation rules. For example, we can pass config like below to let all vars stars wth digit to autofill in with a real digit, and all vars starts with letter to autofill in with a real letter. And the var with the same name will also be filled with the same value.
      # config
      # {
      #     "digit": lambda: random.choice(string.digits),
      #     "letter": lambda: random.choice(string.ascii_letters),
      # }
      
      # before
      >>> "{digit1} {digit2} {letter2} {digit2}"
      # after
      >>> 8 6 z 6
      
    2. Format and return the content. Put all args we get to the content, and keep those unknown args in original place.

Metadata

Release files for textobfuscator 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for textobfuscator 0.1.3
File Size Uploaded Provenance Actions
TextObfuscator-0.1.3.tar.gz 10.9 kB Without provenance Details for TextObfuscator-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for textobfuscator 0.1.3
File Interpreter ABI Platform Actions
TextObfuscator-0.1.3-py3-none-any.whl Python 3 none any Details for TextObfuscator-0.1.3-py3-none-any.whl

Total release size: 23.0 kB

Release files / TextObfuscator-0.1.3.tar.gz

Download URL TextObfuscator-0.1.3.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a338afdec53f91b4562bcb8086505a36b25a20cfc90b3612c74fef03c1ef3987
BLAKE2b-256 checksum
How to use checksums
8f7f40369e9d5d9e096f03d4a47f0e235f65d57e240fc29011d6e05bd842b760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.7 Darwin/22.1.0

Release files / TextObfuscator-0.1.3-py3-none-any.whl

Download URL TextObfuscator-0.1.3-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c4dfbc205c0b0a1856f9f236d4d71b97ebbc5a78a543b536a99f2ed875ae2d2
BLAKE2b-256 checksum
How to use checksums
bed578ef7e014f93d5f004a22b1d8f3d65fb2bd4162ca0eee6d95c286bd0b535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.7 Darwin/22.1.0

Security for textobfuscator 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page