Skip to content

Instantly share code, notes, and snippets.

@henkman
Created January 5, 2015 19:45
Show Gist options
  • Save henkman/56177360dfcfd530aa5f to your computer and use it in GitHub Desktop.
Save henkman/56177360dfcfd530aa5f to your computer and use it in GitHub Desktop.
def decode(text):
reps = {" ":"0", "\t":"1"}
s = [
y for y in
"".join(
[reps[x] if x in reps else x for x in text]
).split("\n")
if len(y)>0
]
return "\n".join(
[
"".join(
[chr(int(p[x:x+8], 2)) for x in range(0, len(p), 8)]
)
for p in s
]
)
def encode(text):
reps = {"0":" ", "1":"\t"}
s = [x for x in text.split("\n") if len(x)>0]
return "\n".join([
"".join([
reps[y] for y in
"".join([
"{0:08b}".format(ord(x)) for x in p
])
]) for p in s
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment