Page 3 of 5

Re: LSB (Least Significant Bit) File Embedding

Posted: Fri Oct 14, 2016 9:15 am
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)

Re: LSB (Least Significant Bit) File Embedding

Posted: Fri Oct 14, 2016 5:12 pm
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).

Re: LSB (Least Significant Bit) File Embedding

Posted: Fri Oct 14, 2016 7:08 pm
by walbus
Hi JHPJHP,
looking very good

Best regards Werner

Re: LSB (Least Significant Bit) File Embedding

Posted: Fri Oct 14, 2016 7:44 pm
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.

Re: LSB (Least Significant Bit) File Embedding

Posted: Sat Oct 15, 2016 3:55 am
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 ^^)

Re: LSB (Least Significant Bit) File Embedding

Posted: Sat Oct 15, 2016 4:19 am
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.

Re: LSB (Least Significant Bit) File Embedding

Posted: Sat Oct 15, 2016 7:14 am
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.

Re: LSB (Least Significant Bit) File Embedding

Posted: Sat Oct 15, 2016 7:45 am
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....

Re: LSB (Least Significant Bit) File Embedding

Posted: Mon Oct 17, 2016 1:56 am
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.

Re: LSB (Least Significant Bit) File Embedding

Posted: Mon Oct 17, 2016 11:27 am
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

Re: LSB (Least Significant Bit) File Embedding

Posted: Mon Oct 17, 2016 2:32 pm
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.

Re: LSB (Least Significant Bit) File Embedding

Posted: Sat Oct 29, 2016 3:43 am
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.

Re: LSB (Least Significant Bit) File Embedding

Posted: Sun Oct 30, 2016 8:42 pm
by walbus
Very nice News JHPJHP

Re: LSB (Least Significant Bit) File Embedding

Posted: Mon Oct 31, 2016 2:13 am
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

Re: LSB File Embedding

Posted: Tue May 28, 2019 4:20 am
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