If I have understood it corretly you want binary equivalent of string like 'hello'
to ['1101000', '1100101', '1101100', '1101100', '1101111']
each for h e l l o
import base64
some_text = input('enter a string to be encoded(8 bit encoding): ')
def encode(text):
base64_string = (base64.b64encode(text.encode("ascii")))
return ''.join([bin(i)[2:].zfill(8) for i in base64_string])
def decode(binary_digit):
b = str(binary_digit)
c = ['0b'+b[i:i+8] for i in range(0,len(b), 8)]
c = ''.join([chr(eval(i)) for i in c])
return base64.b64decode(c).decode('ascii')
encoded_value = encode(some_text)
decoded_value = decode(encoded_value)
print(f'encoded value of {some_text} in 8 bit encoding is: {encoded_value}')
print(f'decoded value of {encoded_value} is: {decoded_value}')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…