I have made a Python script to generate random binary strings, then convert those into ASCII.
from random import *
def decode(binary):
# credit to mhawke from stack overflow
return ''.join(chr(int(binary[i*8:i*8+8],2)) for i in range(len(binary)//8))
def generate_random_binary(chars=None):
if not chars:
chars = randint(10, 20)
r = ''
for i in range(chars * 5):
num = choice(['0', '1'])
r = r + num
return r
generated = generate_random_binary(64)
decoded = decode(generated)
decoded = eval("r'''"+decoded.replace('\0', '')+"'''")
print(decoded.replace('\n', ''))
Sometimes I get output with newlines, even though I tried to remove those. Is there something I'm missing?
Here's an example of my output (ran in Repl.it):
ìîù_½ Ý05!d(óÞÉ|½b°L³µ¬
H}N¸'Ä