Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encryption.. Idea...

Status
Not open for further replies.

klibby

Programmer
May 30, 2001
51
0
0
US
I saw the movie "Along Came the Spider" a couple days ago... and I got an idea from it. In the movie they used an encryption technique where information.. text... was stored in an image. I thought I had heard about something like this, but I cant seem to find anything.

If this does not exist... I'm thinking about trying, if I do try I'm asking for help if anybody wants to join in on creating something like this. My ideas are to use an offset in the image somewhere... So, when you try to open the image, it would open like normal and show a picture, nothing else. That picture would of course be somewhat distorted in the areas where the offset was made (hopefully I can make distortion minimal).... but when you open it in the decryption software with the given password it will display the text encrypted in the image.


Anybody know if there's anything out there like this already so I dont waste my time?
 
Do a search on the internet for steganography.
 
Hi Klibby!

I wrote a couple of encryption/decryption algorithms that work similar to your idea, but into a dummy text file. Here's how it works, I think it may give you some ideas.
The encrypter opens the file and prints 255 (more if necessary) randomly generated ASCII characters to provide the hiding place. Then it generates random numbers to determine wheather it will shift the ASCII values up or down, by how much, and the starting location in the text file (all generated with carefully chosen parameters to avoid writing past EOF, or writing to where the retrieval information will be). This information, the length of the string (all numbers), and the string itsself, is placed into pre-selected locations in the file. The decrypter knows where to look for the retrieval information, and from there it's reverse engineering.
This is based mainly on the idea that the encrypter will shift the characters in such a way that the string will not appear as an anomoly in the text file, even when viewed with a hex editor. This could be a challenge with a bitmap. Even four contiguous characters would be visible if their ASCII values translate to the wrong colors. Neon green on a black background would be my luck :)
One way to get around this may be to use GetPixel to read the color values of each bit where it will be written, determine the average, and encrypt the string so that the average of the string's values most closely matches the color average (did I say this would be a challenge?)
Another way would be to break the string into individual characters, each printed in a separate location in the bitmap. You may even get away with hard coding the locations, since only one pixel would be affected at a time. I think that mostly depends on the bitmap used.
One more thing to be aware of is that bitmap images have 5 different sections in the file, and only one defines the actual bits that make the picture. Writing to any of the others will probably make it unreadable. The others are header info and the like. Check out for more on that.

Hope that gives you some insight and ideas!

-Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
The following isn't exactly steganography but it provides a way to store data in a BMP file without degrading the quality of the image. You would probably want to subject the data to some decent encryption before you store it.

Add two Command buttons, a Text box and a Picture box to a form and set the picture property on the Picture box to some BMP on your system.

Click Command1 to write the contents of Text1 to the BMP file. Click Command2 to read from the file and place the data in Text1.
Code:
Private Sub Form_Load()
Command1.Caption = "Write Data In Text1 To BMP"
Command2.Caption = "Populate Text1 With Data Stored In BMP"
Text1.Text = "Example of data to store in BMP file."
' Place a BMP file in the app folder
SavePicture Picture1.Picture, App.Path & "\" & "MyPicture.bmp"
End Sub

Private Sub Command1_Click()
Fname$ = App.Path & "\" & "MyPicture.bmp"
' Get the physical file size.
TotalSize& = FileLen(Fname$)
ff = FreeFile
Open Fname$ For Binary As #ff
' Get the original file size.
Get #ff, 3, ImageSize&
If TotalSize& > ImageSize& Then
    ' File already contains data.
    x = MsgBox("Write over existing data?", vbYesNo)
    If x <> vbYes Then
        Close
        Exit Sub
    End If
End If
Pu$ = Text1.Text
' Append the contents of Text1 to the file.
Put #ff, ImageSize& + 1, Pu$
Close #ff
End Sub

Private Sub Command2_Click()
Text1.Text = &quot;&quot;
Fname$ = App.Path & &quot;\&quot; & &quot;MyPicture.bmp&quot;
' Get the physical file size.
TotalSize& = FileLen(Fname$)
ff = FreeFile
Open Fname$ For Binary As #ff
' Get the original file size.
Get #ff, 3, ImageSize&
If TotalSize& <= ImageSize& Then
    MsgBox &quot;Picture doesn't contain data.&quot;
    Close
    Exit Sub
End If
Ge$ = String$(TotalSize& - ImageSize&, 32)
' Retrieve the previously stored data.
Get #ff, ImageSize& + 1, Ge$
Close #ff
Text1.Text = Ge$
End Sub
I hope this gives you even more ideas....


VCA.gif
 
Nicely done.

I can't figure out why yet, but if you recycle the application and try to read the written data, it doesn't find it. But like you said, even with the app running and having written to the picture, I couldn't tell any difference in the bitmap, since it's appended.

-Mike Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
It overwrites MyPicture.bmp every time the form loads.

You would probably want to remove the SavePicture command and deal with pre-existing BMPs. I only included the command to provide a starting point with a known file.

Have fun.

BTW, there are a number of other file formats that allow this sort of data storage without affecting the functionality of the files.
VCA.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top