Skip to content

Instantly share code, notes, and snippets.

@iivvoo
Last active January 5, 2020 15:03
Show Gist options
  • Save iivvoo/0381dd3452b7b4403d38eaec78d6bb33 to your computer and use it in GitHub Desktop.
Save iivvoo/0381dd3452b7b4403d38eaec78d6bb33 to your computer and use it in GitHub Desktop.
A simple pythonscript to encode ascii text to whitespace and back
#!/usr/bin/env python3
import sys
spaces = " \u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000"
def encode(s):
res = ""
for c in s:
c = ord(c)
res += spaces[(c & 0xf0) >> 4]
res += spaces[c & 0x0f]
return res
def decode(ws):
res = ""
for (a,b) in zip(ws[::2], ws[1::2]):
res += chr(spaces.index(a)*16+spaces.index(b))
return res
if len(sys.argv) == 1:
print("Usage: {} [string_to_encode|string_to_decode]")
elif all(c in spaces for c in sys.argv[1]):
print('Decoded to "{}"'.format(decode(sys.argv[1])))
else:
print("Encoded between [] -> [{}]".format(encode(sys.argv[1])))
@iivvoo
Copy link
Author

iivvoo commented Jan 5, 2020

The same script, whitespace encoded:

   ᠎                                                                         ᠎                     ᠎                             ᠎                                                                                                           ᠎                                                                                                                                                                                                             ᠎                                                                             ᠎                                                                                                                                         ᠎                                               ᠎                                                         ᠎                     ᠎     ᠎         ᠎                                                                                   ᠎                 ᠎                               ᠎                                                                                                     ᠎                     ᠎                                   ᠎         ᠎                                                                         ᠎                           ᠎         ᠎                                                                                                             ᠎                           ᠎         ᠎        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment