python - Steganographer File Handling Error for non plain-text files

前端 未结 1 1662
一整个雨季
一整个雨季 2020-12-21 19:18

I\'ve built a Python Steganographer and am trying to add a GUI to it. After my previous question regarding reading all kinds of files in Python. Since, the steganographer ca

相关标签:
1条回答
  • 2020-12-21 19:43

    You can use and end-of-stream (EOS) marker when you are certain the marker sequence will not show up in your message stream. When you can't guarantee that, you have two options:

    • create a more complicated EOS marker, comprised of many bytes. This can be quite the nuisance to prove the same problem won't arise as before, or
    • Add a header at the beginning of your message, which encodes how many bits/bytes to read for the complete message extraction.

    Generally, I'd use a header whenever I have information beforehand that I want to transmit and only rely on EOS markers when I don't know when my byte stream will terminate, e.g., on-the-fly compression.

    For embedding, you should aim to:

    • get your binary string
    • measure its length
    • convert that integer to a binary of fixed size, say, 32 bits
    • attach that bitstring in front of your message bitstring
    • embed all of that to your cover medium

    And for extraction:

    • extract the first 32 bits
    • convert those to an integer to get your message bitstring length
    • start from index 32 and extract the neccessary number of bits
    • convert back to a bytestream and save to a file

    As a bonus, you can add all sorts of information to your header, e.g., the name of the original file. As long as it's all encoded in a way you can extract it later. For example.

    header = 4 bytes for the length of the message string +
             1 byte for the number of characters in the filename +
             that many bytes for the filename
    
    0 讨论(0)
提交回复
热议问题