0

i want to hide a .txt file to a picture, but i don't want to using stegano because i already use it and if i using the stegano again it will overwrite the data. so i wanna used something like How do I hide a file inside an image with Python?

and i tried using the answer on that questions

out=file("makan.png","wb")
out.write(file("sudah.png","rb").read())
out.write(file("cipher.txt","rb").read())
out.close()

but it says file is not defined, can anyone explain this? im beginner in python im so sorry

1 Answers1

0

Just replace file with open. Also you can use with so you don't need to call close at the end:

with open('makan.png', 'wb') as out:
    out.write(open('sudah.png', 'rb').read())
    out.write(open('cipher.txt', 'rb').read())

Extracting text from image:

with open('makan.png', 'rb') as f:
    text = f.read().split(b'IEND\xaeB`\x82')[1].decode('utf-8')
Alderven
  • 7,569
  • 5
  • 26
  • 38