Text Obfuscator
Obfuscate your message with Text Obfuscator
Installation
pip install -U textobfuscator
Usage
import random
from textobfuscator.obfuscator import TextObfuscator
CHARS_GROUPS_SOURCE_MAP = (
["😯", "🤣"],
["❌", "✅"],
)
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
BREAK_WORDS_RULES = [
BreakWord(word="hello", places=2, fill="*"),
BreakWord(word="world", places=1, fill="-"),
]
OBFUSCATOR_CONFIG = ObfuscationConfig(
replaces=Replace(count=1),
break_words=BREAK_WORDS_RULES,
)
>>> 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.
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.
>>> "{digit1} {digit2} {letter2} {digit2}"
>>> 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.