Skip to content
Advertisement

How to decode binary content to original string content in python?

I have a string which I need to encode into binary. It is very important that I get a value string like ‘11010011100…’, because later I need to insert it into the lowest bit of pixels of a gray scale image. (Basically I am hiding a message inside an image.) I am on windows 10, using python 3.6.8.

Following this link I wrote this method to encode it:

JavaScript

Output is: 1001000110010111011001101100110111110000011101111101111111001011011001100100

Now I want to have a method to take this binary stream and make the original message like:

JavaScript

I tried the following:

JavaScript

But the output is again:

JavaScript

Also I don’t understand why the length of the binary message is 76 and not 78? First of all it takes each character into 7 bits and not 8, which I don’t understand why. Also even with 7 bits, ‘Hello world’ has 11 characters, so I expect length 77, but it is giving me 76? Can someone please explain this to me?

JavaScript

Thank you all for your valuable input.

Advertisement

Answer

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement