Wireless Army
This is a blog / tips and tricks website for web developers and security researchers.
follow us in feedly

binary to text
by admin
 at 2015-12-15 08:07:00.

if you want to get the text version of a binary you can use the code bellow:
#!/usr/bin/env python

BITS = ('0', '1')

def seq_to_bits(seq):
    return [0 if b == '0' else 1 for b in seq]

def bits_to_char(b):
    assert len(b) == ASCII_BITS
    value = 0
    for e in b:
        value = (value * 2) + e
    return chr(value)

def list_to_string(p):
    return ''.join(p)

def bits_to_string(b):
    return ''.join([bits_to_char(b[i:i + ASCII_BITS]) 
                    for i in range(0, len(b), ASCII_BITS)])

bittostring = raw_input("Enter something: ")
print bits_to_string(seq_to_bits(bittostring))