Click here to Skip to main content
12,897,830 members (75,886 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 15 Oct 2013

Embed Messages in Images, The Easy Way!

, 15 Oct 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Embed secret messages in image files using Autohotkey.


The idea of embedding secret messages on images is not new, in fact this has been done many times by many people. Some are so complex that even experts in Steganography won’t be able to decrypt them. I’ve used a simple method to do this. Data can be written into files in binary mode without modifying the initial contents of the file. This is the basic idea of my implementation.

My implementation is quite simple and can be explained in three simple steps. I’ve used Autohotkey for coding it because it is quite simple and I often use it because of its simplicity and power. If this was done in any mainstream programming language like C/C++, it would take almost twice or thrice the number of code lines. Autohotkey, which is a scripting language originally developed for automating keystrokes and mouseclicks, was taken to the next level by the community. Now, autohotkey is one of the most powerful scripting languages known, which is capable of doing almost everything a normal programming language can do.

The algorithm for the encryptor can be explained like this:

Algorithm For Encryption

Yes, it is as simple as this! Writing to file is the tricky part, the FileAppend command in Autohotkey supports writing in binary mode, which will not corrupt the file being written. The encrypted message is written at the end of the file. If the same image is used, the previous message will be lost (the program may be modified to read all the messages with some minor changes).

Decrypting Data From the Image

The data written onto the image file can be retrieved by reading the last line from the file and decrypting it using the key that was used to encrypt the message.

Decryption Algorithm

Only the last line of the file is read, meaning if the same image is used before, the message which was added last will be read and decoded. There is no check done to verify whether the image contains any data, but that can be implemented easily with a few lines of code in Autohotkey. 


The code for embedding the message: 

;Simple Message Embedding - Encryptor
InputBox,data,Enter Message,Enter The Message To Be Embedded Into The Image
InputBox,pass,Enter Encyrption Key,Enter Password To Encrypt
FileSelectFile, SelectedFile, 3, , Select an image, Image Files (*.jpg; *.png)
if SelectedFile =
    MsgBox, Select A File!
    MsgBox,The Message will be hard coded into the file :`n%SelectedFile%
Msgbox,0,Done,The Message Was Embedded!
;Function To Encrypt The Message
Encrypt(Data,Pass) { 
	Format := A_FormatInteger 
	SetFormat Integer, Hex 
	b := 0, j := 0 
	Loop 256 
		a := A_Index - 1 
		,Key%a% := Asc(SubStr(Pass, Mod(a,StrLen(Pass))+1, 1)) 
		,sBox%a% := a 
	Loop 256 
		a := A_Index - 1 
		,b := b + sBox%a% + Key%a%  & 255 
		,sBox%a% := (sBox%b%+0, sBox%b% := sBox%a%) ; SWAP(a,b) 
	Loop Parse, Data 
		i := A_Index & 255 
		,j := sBox%i% + j  & 255 
		,k := sBox%i% + sBox%j%  & 255 
		,sBox%i% := (sBox%j%+0, sBox%j% := sBox%i%) ; SWAP(i,j) 
		,Result .= SubStr(Asc(A_LoopField)^sBox%k%, -1, 2) 
	StringReplace Result, Result, x, 0, All 
	SetFormat Integer, %Format% 
	Return Result 

Points of Interest

The implementation is bound to certain limitations. The first one, like other ones out there, is the loss of message during conversion or resizing. The encryption I have used here is not powerful enough. No check is performed for the existence of messages on file.

Happy embedding! ;-)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

India India
I'm a engineering student specializing in Computer Science. I'm passionate about programming & electronics.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 15 Oct 2013
Article Copyright 2013 by Aravind.V.S
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid