PureBasic Forum
http://forums.purebasic.com/english/

LSB File Embedding
http://forums.purebasic.com/english/viewtopic.php?f=12&t=64016
Page 3 of 3

Author:  walbus [ Fri Oct 14, 2016 9:15 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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:
UseCRC32Fingerprint()

password1$="Hello"
password2$="World"
result$=password1$+password2$+"salt_&%)?//``/c"
result=Val("$"+Fingerprint(@result$, StringByteLength(result$), #PB_Cipher_CRC32))
Debug result
RandomSeed(result)

Author:  JHPJHP [ Fri Oct 14, 2016 5:12 pm ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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).

Author:  walbus [ Fri Oct 14, 2016 7:08 pm ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

Hi JHPJHP,
looking very good

Best regards Werner

Author:  JHPJHP [ Fri Oct 14, 2016 7:44 pm ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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.

Author:  Lunasole [ Sat Oct 15, 2016 3:55 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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 ^^)

Author:  JHPJHP [ Sat Oct 15, 2016 4:19 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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.

Author:  netmaestro [ Sat Oct 15, 2016 7:14 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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

One thing I noticed, how are you squaring this:

Code:
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.

Author:  walbus [ Sat Oct 15, 2016 7:45 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

@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/viewtopic.php?f=14&t=43141&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_Block_Chaining_Mode

And unfortunately, using CBC is not ever the best idea....

Author:  JHPJHP [ Mon Oct 17, 2016 1:56 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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.

Author:  walbus [ Mon Oct 17, 2016 11:27 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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:
AESEncoder(*IV, *IV, 16, *Key, 256, 0, #PB_Cipher_ECB)


IV creating with a structure is not needed
Simplest so , i think..
Code:
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:
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

Author:  JHPJHP [ Mon Oct 17, 2016 2:32 pm ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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.

Author:  JHPJHP [ Sat Oct 29, 2016 3:43 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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.

Author:  walbus [ Sun Oct 30, 2016 8:42 pm ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

Very nice News JHPJHP

Author:  JHPJHP [ Mon Oct 31, 2016 2:13 am ]
Post subject:  Re: LSB (Least Significant Bit) File Embedding

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

Author:  JHPJHP [ Tue May 28, 2019 4:20 am ]
Post subject:  Re: LSB File Embedding

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

Page 3 of 3 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/