Search code examples
pythonpython-3.xsteganography

How to encode a string using zero width steganography


I am running Python 3.7.x and am trying to figure out how to encode a string, {CTF-FLAG1}, using zero width steganography.

I am using zwsp-steg-py to do so, but I do not know how to use this to encode text into other text, see below:

I want to encode {CTF-FLAG1} inside of the text Now you see me, now you don't. using zero width steganography.

I installed zwsp-steg-py and tried:

#coding=utf-8
import zwsp_steg
encoded = zwsp_steg.encode("{CTF-Flag1}", zwsp_steg.MODE_ZWSP)

decoded = zwsp_steg.decode(encode​​​​​​​‍‌‌‌​​​​​​‌​​‌​​​​​​​​‍‌‍‌​​​​​​​‌‍​​​​​​​​​‍‌‍‌​​​​​​‌‌​​​​​​​​​‌​‌‍‌​​​​​​‌​‍‌‌​​​​​​​‌‍‌‌)
print(decoded)

Yet, the result is:

C:\Users\jerry\Desktop>python decode.py
Traceback (most recent call last):
  File "decode.py", line 5, in <module>
    decoded = zwsp_steg.decode(encoded)
  File "C:\Python367-64\lib\site-packages\zwsp_steg\steganography.py", line 72, in decode
    raise TypeError('Unknown encoding detected!')
TypeError: Unknown encoding detected!

I don't think I'm doing it right.


Solution

  • #coding=utf-8
    import zwsp_steg
    encoded = zwsp_steg.encode("{CTF-Flag1}", zwsp_steg.MODE_ZWSP)
    
    decoded = zwsp_steg.decode(encode​​​​​​​‍‌‌‌​​​​​​‌​​‌​​​​​​​​‍‌‍‌​​​​​​​‌‍​​​​​​​​​‍‌‍‌​​​​​​‌‌​​​​​​​​​‌​‌‍‌​​​​​​‌​‍‌‌​​​​​​​‌‍‌‌, zwsp_steg.MODE_ZWSP)
    print(decoded)
    
    # example with string padding
    
    encoded += "This is a test string"
    print(encoded)
    decoded_the_string = zwsp_steg.decode(encode​​​​​​​‍‌‌‌​​​​​​‌​​‌​​​​​​​​‍‌‍‌​​​​​​​‌‍​​​​​​​​​‍‌‍‌​​​​​​‌‌​​​​​​​​​‌​‌‍‌​​​​​​‌​‍‌‌​​​​​​​‌‍‌‌, zwsp_steg.MODE_ZWSP)
    print(decoded_the_string)