python 3.x - Python3 utf-8 decoding/encoding problems with data hiding -


i'm trying take text file (the text russian), hide in image, , later able retrieve image. however, keep getting binascii.error: odd-length string when try retrieve data image hid in.

i feel problem may lie within use hide text. when somestring = file.read() on file, , print somestring comes out fine. when run:

file = open(<text file path>, 'r', encoding='utf-8') entiretext = file.read() print(codecs.encode(entiretext,'utf-8'))

i following:

b'\xd0\x9f\xd1\x80\xd0\xb8\xd0\xbf\xd0\xb5\xd0\xb2:\n\xd0\x9e\xd1\x87\xd0\xb8 \xd1\x87\xd1\x91\xd1\x80\xd0\xbd\xd1\x8b\xd0\xb5, \xd0\xbe\xd1\x87\xd0\xb8 \xd0 

that piece of it, theme shown; has colons, spaces, commas, , \n throughout 'bytes' type codecs.encode returns. if use codecs decode it, original text in perfect format.

if helps, here functions use make happen:

def stringtobinary(msg): return bin(int(binascii.hexlify(msg.encode('utf-8')), 16))[2:]  def binarytostring(bnum):     return binascii.unhexlify('%x' % (int('0b' + bnum, 2))).decode('utf-8') 

if not enough, entire file here: http://pastebin.com/f541dpzs

edit: think i'm getting issue because image i'm trying hide text in didn't have enough pixels me hide complete message, trying convery binary number string without of bits, throwing binascii.error: odd-length string.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -