Skip to content

Instantly share code, notes, and snippets.

@gabrielgrant
Created May 24, 2013 19:11
Show Gist options
  • Save gabrielgrant/5645838 to your computer and use it in GitHub Desktop.
Save gabrielgrant/5645838 to your computer and use it in GitHub Desktop.
hidden_bin_string = '01011001001100110101011001110111011000100011' \
'001000110100011001110101100100110010001110010110101101011010' \
'010101000110111101100111010100110101010100110001010101000101' \
'010000110000011110000100011001010010010101100101000101100111' \
'01001111011110010110101100111101'
from itertools import groupby
from base64 import b64decode
bit_counts = [0]
def grouper(x):
""" groups bits into bytes """
cur_bit_count = bit_counts[-1]
bit_counts.append(cur_bit_count + 1)
return cur_bit_count / 8
chr_bit_groups = groupby(hidden_bin_string, grouper) # bits -> bytes
chr_bit_strs = [''.join(v) for i,v in chr_bit_groups] # join byte strs
chr_vals = [int(s, base=2) for s in chr_bit_strs] # convert to ints
base64_code = ''.join(chr(i) for i in chr_vals) # convert to chrs
print b64decode(base64_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment