LSB Image Steganography

Developed or developing a new product in PureBasic? Tell the world about it.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: LSB (Least Significant Bit) File Embedding

Post by walbus »

Hi,
nice too see new features
I have maked a quick look in your code, and see, you generate the IV with RandomSeed(0)
I think, it is simple for coupling your passwords with this,
so you become a automatic changed IV, a static IV is not a good idea, i think...

As sample :

Code: Select all

UseCRC32Fingerprint()

password1$="Hello"
password2$="World"
result$=password1$+password2$+"salt_&%)?//``/c"
result=Val("$"+Fingerprint(@result$, StringByteLength(result$), #PB_Cipher_CRC32))
Debug result
RandomSeed(result)
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: LSB (Least Significant Bit) File Embedding

Post by JHPJHP »

Hi walbus,

Thank you for the information, a dynamic seed makes a lot more sense.

-------------------------------------------------------

Updated:
- replaced the static seed with a dynamic seed

-------------------------------------------------------

Updated:
- fixed an issue in the Header Password algorithm

1. Open the application and enter a custom Header Password and Bit Password.
2. Embed a file.
3. Save the image.
4. Close the application.
5. Open the application, but only enter the previously used Header Password.
6. Open the previously saved image.
7. You're able to view information on the embedded file, but extracting the file is still encrypted.
8. Each embedded file (bit) can have a different Bit Password (change password before embedding next file).
Last edited by JHPJHP on Tue Feb 27, 2018 5:20 am, edited 1 time in total.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: LSB (Least Significant Bit) File Embedding

Post by walbus »

Hi JHPJHP,
looking very good

Best regards Werner
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: LSB (Least Significant Bit) File Embedding

Post by JHPJHP »

Hi walbus,

Thank you for your comments and support.

--------------------------------------------------

Updated:
- added Show Password option to the Header / Bit Security window

This was added to help avoid mis-keying a password.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: LSB (Least Significant Bit) File Embedding

Post by Lunasole »

Hi. Tnx for interesting stuff, time ago I did many own experiments this way, but never made some finished program (maybe because never really needed it). Anyway all such things are always interesting to play with :3

Btw, there is something like a bug after brief testing:
- I've used default.jpg, packed text file (95 bytes size) into it, saved to PNG, then reloaded saved image and extracted file: the output text file was 256 bytes with space above 95 bytes filled using zeros.

(hope I'm not repeating someone's else post about this, as I didn't read whole topic before posting ^^)
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: LSB (Least Significant Bit) File Embedding

Post by JHPJHP »

Hi Lunasole,

Thank you for testing the application and posting your results; the bug has been squashed :)

---------------------------------------------------------

Updated:
- fix a bug where files smaller then 256 bytes were padded with zeros :: reported by Lunasole

NB*: Update also includes a small change affecting OSX users.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: LSB (Least Significant Bit) File Embedding

Post by netmaestro »

Very good work! Also fun to play around with. Thanks for sharing it.

One thing I noticed, how are you squaring this:

Code: Select all

Structure InitializationVector
  b.a[32]
EndStructure
with this:
PB doc wrote:*InitializationVector: The InitializationVector is a random data block, used to initialize the ciphering to avoid breach in decoding (only needed when using the #PB_Cipher_CBC mode). The initialization vector is always 16 bytes long.
BERESHEIT
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: LSB (Least Significant Bit) File Embedding

Post by walbus »

@netmaestro
I self think, he has this simple oversight, it has not a negative effect.
The best way is adding a other crypt randomized IV to each file to encrypt

Friendly hint : This should you change also in your own tool, i think... :wink:
http://www.purebasic.fr/english/viewtop ... 1&start=45

A complete tool how not change immediately the IV is absolutely not a good idea

In older PB documentation the IV was false with 32 bytes specified
And to time, i think the documentation should a explanation what the IV is and what he exactely do

So, many users use the IV false, or think he make wonders

How one make more, it is interesting for looking in the Wikipedia how it works and what it exactely do
This is also the 'key' for understanding how other cypher modes primary works
https://de.wikipedia.org/wiki/Cipher_Bl ... ining_Mode

And unfortunately, using CBC is not ever the best idea....
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: LSB (Least Significant Bit) File Embedding

Post by JHPJHP »

Hi netmaestro,

Thank you for your comments and correction.
- I was originally using the DataSection included in the documentation until I found this older post by you: [PB 4.40] AES encryption: Streaming demo :mrgreen:

Your words, contributions, and support are very much appreciated:
netmaestro wrote:Some years ago I adopted a policy of always sharing source code for projects released on the forums, for a couple of good reasons. One, coders on the forum including me are here to learn and pick up new skills in PureBasic. If people are releasing libraries and programs without source, the collaboration benefits to everyone are lost. Sharers benefit too by getting useful critique from other coders and learning to do things in a more polished or efficient way.
BTW: Windows Cryptor is very impressive with some nice graphics and sound effects.

-------------------------------------------------------------------

Hi walbus,

Thank you for the additional information: Block cipher mode of operation (English version).

-------------------------------------------------------------------

Updated:
- modified the InitializationVector Structure as posted by netmaestro
- fixed an issue in the Drag and Drop Procedure

Something you might find interesting:
- open the application, close the password window (not relevant with this demo)
- click the first bit (far left: bit 7)
- embed a file (EmbedLSB.pb is suitable for this demo)
- double-click the main image to open a visual representation of the changes

The modified bits should be noticeable in both the encrypted header and body.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: LSB (Least Significant Bit) File Embedding

Post by walbus »

Hi JHPJHP
You can optimize your IV before using, so :
(Sorry, i have forget this last step)
This encrypt the IV with your used key, i'ts 100% OK

Code: Select all

AESEncoder(*IV, *IV, 16, *Key, 256, 0, #PB_Cipher_ECB)
IV creating with a structure is not needed
Simplest so , i think..

Code: Select all

Dim IV.q (1)
RandomData(@IV(0), 16)
Creating the 32Byte Key from Ascii here reduce the Key komplexity to 16 Bytes
Creating the 32Byte Key from a 256Bit hash as sample so :

Code: Select all

ii=0 ; Create a 32Byte Key from a 256Bit hash(Ascii and Unicode)
For i = 0 To 31 : PokeA(@IV(0)+i, Val("$"+PeekS(@key$+ii, 2))) : ii+SizeOf(character)<<1 : Next
Also, a little,
The dialog extract file > break, break not directly

Regards Werner
Last edited by walbus on Mon Oct 17, 2016 3:07 pm, edited 2 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: LSB (Least Significant Bit) File Embedding

Post by JHPJHP »

Hi walbus,

Thank you for your new post.

I really like the idea of encrypting the IV with the Key, and have adopted it into the application.

I know a Structure isn't needed, but I still prefer it.

I believe I'm already creating a 32 byte Key from a 256 bit hash by using Fingerprint with #PB_Cipher_SHA3.

------------------------------------------------------

Updated:
- modified the AES_EncoderDecoder Procedure and the AES_CipherBuffer Procedure
- fixed a bug in the Button3Handler Procedure

NB*: Changes were based on recommendations provided by walbus.
Last edited by JHPJHP on Tue Feb 27, 2018 5:22 am, edited 2 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: LSB (Least Significant Bit) File Embedding

Post by JHPJHP »

Updated:
- added direct folder embedding
-- new button and context menu item
- updated Drag and Drop to include folders
- added multi selection when embedding files
- brought back the compression algorithm (bug fix)
-- results returned to the information area: EMBEDDED SIZE
- added shortcut keys
-- Left / Right Arrow: change the active bit
-- Escape Key: close the password window / exit the application
- applied a few cosmetic changes
- fixed a couple hidden bugs

Using the new folder embedding feature on the default image, I was able to embed the folder OpenCV_32 (no subfolders) containing over 240 script files into a single bit.

NB*: It may be worth noting that errors were only evident after Purifier was enabled.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: LSB (Least Significant Bit) File Embedding

Post by walbus »

Very nice News JHPJHP
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: LSB (Least Significant Bit) File Embedding

Post by JHPJHP »

Hi walbus,

Thank you for the comment.

------------------------------------------------------------

Updated:
- set a cap on the precompression folder size test
- more detailed message information
- added additional prompts
-- overwriting bits, overwriting files, overwriting folders
- applied a few cosmetic improvements
Last edited by JHPJHP on Tue Feb 27, 2018 5:22 am, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: LSB File Embedding

Post by JHPJHP »

Updated:
- for PureBasic 5.60 +
-- compatibability with previous versions has been removed

----------------------------------------------------------

Updated (Windows):
- image sizes configured to use the built-in PureBasic DPI compiler option
Locked