I am trying to implement DES algorithm in Python. After the encryption phase I got bit string as "0010100100110100011001010011011101110111011110011000100010100011"
. Now I want to convert this bit string to bytes and write the data into the file. But the problem, is it contains non-readable characters. When I try to convert this into string, I got )4e7wy£
and for doing so, I am using
def bits2String(b):
return ''.join(chr(int(''.join(x), 2)) for x in zip(*[iter(b)]*8))
And further when I convert string to bytes, it adds extra characters which I don't want. So, how I can perform above task so that )4e7wy£
can be as it is written in file in binary mode.