Text obfuscator.
Project description
Text Obfuscator
Obfuscate your message with Text Obfuscator
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, ObscureConfig, 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` twice, and put `-` into the middle, like `wor-ld`
BreakWord(word="world", places=1, fill="-"),
]
OBFUSCATOR_CONFIG = ObscureConfig(
# 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
- Split content into segments by every args position.
- Break words.
- Break words on each segment.
- Merge all segments and put back all key args in places.
- Replace.
- Temporarily remove all key args.
- Replace matching chars according to the given mapping table and config.
- Put back all key args that removed on above in places.
- Format.
- Merge the
pre-defined
key args and given key args. Herepre-defined
args means we can create custom var generation rules. For example, we can pass config like below to let all vars stars wthdigit
to autofill in with a real digit, and all vars starts withletter
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
- Format and return the content. Put all args we get to the content, and keep those unknown args in original place.
- Merge the
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
TextObfuscator-0.1.0.tar.gz
(10.9 kB
view details)
Built Distribution
File details
Details for the file TextObfuscator-0.1.0.tar.gz
.
File metadata
- Download URL: TextObfuscator-0.1.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.8.7 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3db7127d6426235dc41b29eedb07c21f3a1379945378e50dc225ffb0aab1776 |
|
MD5 | 8bda672e4240b6dc234481f85628373c |
|
BLAKE2b-256 | a71fe04f5cf61c6423c88cb84b963971db7e3941b265111396096035b5f7514b |
File details
Details for the file TextObfuscator-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: TextObfuscator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.8.7 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcacbc42c0c6c054f9c3232c9f6edfacd404b9dee8aecb3a0fba4f03d4e6aa47 |
|
MD5 | d4b272a46a1c6bafd9074732f6ca7ae8 |
|
BLAKE2b-256 | c206ded30c0eec58d3481f8764a9c9f6277df1f86c444e11c8f3e2a78920a9a4 |