Last active
August 29, 2015 14:14
-
-
Save skurmedel/bd45a00322eb9ca067d3 to your computer and use it in GitHub Desktop.
A little python module and script that makes text much less legible by character encoding conversions and random bit flipping. The bit flipping is not deterministic so you can run it several times and get different results. Works best with languages other than English.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Invoke as: | |
# python mojibakifier.py | |
# | |
# For example: | |
# echo "Hello" | python mojibakifier.py | |
# | |
# Todo: | |
# - Flag for bit_rot | |
import string | |
import sys | |
import random | |
import os | |
def mojibakify(s, bit_rot = True): | |
'''Takes an input string, destroys it and returns a byte object. | |
''' | |
b = s.encode("windows-1252", "ignore") | |
def flipper(x): | |
if random.randint(0, 25) < 2: | |
n = random.randint(0, 8) | |
return x ^ ((3 ** n - 1) % 255) | |
return x | |
if bit_rot: | |
b = bytes(map(flipper, b)) | |
b = b.decode("gbk", "ignore").encode("utf-8", "ignore") | |
return b | |
if __name__ == "__main__": | |
for line in sys.stdin: | |
sys.stdout.buffer.write(mojibakify(line)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment