Skip to content

Instantly share code, notes, and snippets.

@Bondrake
Last active December 20, 2015 21:48
Show Gist options
  • Save Bondrake/6200183 to your computer and use it in GitHub Desktop.
Save Bondrake/6200183 to your computer and use it in GitHub Desktop.
Decode whitespace encoded gif
#!/usr/bin/env python2.7
string = ''
def decodeWhiteChar(char):
if char == '\t': # tab
value = '00'
elif char == '\r': # cr
value = '01'
elif char == '\n': # lf
value = '10'
elif char == ' ': # space
value = '11'
else:
print "\n!!!\t!!!\t!!!\n\n\tbad input!\n\n!!!\t!!!\t!!!\n\n"
sys.exit
return value
with open('poni', 'rb') as pyte_file:
count = 0
t_string = ''
byte = pyte_file.read(1)
while byte != "":
count = (count + 1) % 4
val = decodeWhiteChar(byte)
t_string += val
if count == 0:
binary = int(t_string, 2)
string += chr(binary)
t_string = ''
byte = pyte_file.read(1)
with open('poni.gif', 'wb') as f:
f.write(string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment