473,395 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,395 developers and data experts.

Steganography for VBA

Rabbit
12,516 Expert Mod 8TB
Description
Steganography is the act of hiding a message in plain sight.

How Steganography Works
One popular implementation is to take an existing image file and manipulate the bits to hide a message without noticeably changing the image or increasing the size. It does this by taking each byte that represents a color in a pixel and changing only the last bit.

An uncompressed bitmap file uses three to four bytes to represent each pixel in the image. One for red, one for green, one for blue, and an optional one for alpha. To hide a single ascii character would take 8 bytes. Changing only the last bit of each color ensures that the change is so slight that the human eye would not notice the change in color from picture to picture.

Sample Implementation of Steganography
The following code implements the above example. It only works on uncompressed bitmap images.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Const ForReading = 1, ForWriting = 2, ForAppending = 8
  3. Dim oldFile, newFile, oFS, iSize, strMessage, i, ch, strPath
  4. strPath = InputBox("File Path of Bitmap File:")
  5. Set oFS = CreateObject("Scripting.FileSystemObject")
  6. Set oldFile = oFS.OpenTextFile(strPath, ForReading)
  7.  
  8. If InputBox("1 for encode, 2 to decode") = 1 Then
  9.     Set newFile = oFS.OpenTextFile(Replace(strPath, ".bmp", "-e.bmp"), ForWriting, True)
  10.     iSize = (oFS.GetFile(strPath).Size \ 8) - 1
  11.  
  12.     Do
  13.         strMessage = InputBox("Enter your message. The maximum number of characters is " & iSize & ".")
  14.     Loop Until Len(strMessage) <= iSize
  15.  
  16.     newFile.Write(oldFile.Read(10))
  17.  
  18.     ch = oldFile.Read(1)
  19.     newFile.Write(ch)
  20.     iSize = Asc(ch)
  21.  
  22.     ch = oldFile.Read(1)
  23.     newFile.Write(ch)
  24.     iSize = iSize + Asc(ch) * 256
  25.  
  26.     ch = oldFile.Read(1)
  27.     newFile.Write(ch)
  28.     iSize = iSize + Asc(ch) * 65536
  29.  
  30.     ch = oldFile.Read(1)
  31.     newFile.Write(ch)
  32.     iSize = iSize + Asc(ch) * 16777216
  33.  
  34.     newFile.Write(oldFile.Read(iSize - 14))
  35.  
  36.     For i = 1 To Len(strMessage)
  37.         ch = Asc(Mid(strMessage, i, 1))
  38.  
  39.         newFile.Write(Chr((Asc(oldFile.Read(1)) And 254) Or ((ch And 128) \ 128)))
  40.         newFile.Write(Chr((Asc(oldFile.Read(1)) And 254) Or ((ch And 64) \ 64)))
  41.         newFile.Write(Chr((Asc(oldFile.Read(1)) And 254) Or ((ch And 32) \ 32)))
  42.         newFile.Write(Chr((Asc(oldFile.Read(1)) And 254) Or ((ch And 16) \ 16)))
  43.         newFile.Write(Chr((Asc(oldFile.Read(1)) And 254) Or ((ch And 8) \ 8)))
  44.         newFile.Write(Chr((Asc(oldFile.Read(1)) And 254) Or ((ch And 4) \ 4)))
  45.         newFile.Write(Chr((Asc(oldFile.Read(1)) And 254) Or ((ch And 2) \ 2)))
  46.         newFile.Write(Chr((Asc(oldFile.Read(1)) And 254) Or ((ch And 1) \ 1)))
  47.     Next
  48.  
  49.     For i = 1 To 8
  50.         newFile.Write(Chr(Asc(oldFile.Read(1)) And 254))
  51.     Next
  52.  
  53.     Do Until oldFile.AtEndOfStream
  54.         newFile.Write(oldFile.Read(1024))
  55.     Loop
  56.  
  57.     newFile.Close
  58.     Set newFile = Nothing
  59.  
  60.     MsgBox "Message Encoded!"
  61. Else
  62.     i = 0
  63.     ch = 0
  64.     strMessage = ""
  65.  
  66.     oldFile.Read(10)
  67.     iSize = Asc(oldFile.Read(1))
  68.     iSize = iSize + Asc(oldFile.Read(1)) * 256
  69.     iSize = iSize + Asc(oldFile.Read(1)) * 65536
  70.     iSize = iSize + Asc(oldFile.Read(1)) * 16777216
  71.     oldFile.Read(iSize - 14)
  72.  
  73.     Do Until oldFile.AtEndOfStream
  74.         i = i + 1
  75.         ch = ch Or ((Asc(oldFile.Read(1)) And 1) * (2 ^ (8 - i)))
  76.  
  77.         If i = 8 Then
  78.             strMessage = strMessage & Chr(ch)
  79.             If ch = 0 Then
  80.                 Exit Do
  81.             Else
  82.                 ch = 0
  83.                 i = 0
  84.             End If
  85.         End If
  86.     Loop
  87.  
  88.     MsgBox strMessage
  89. End If
  90.  
  91. oldFile.Close
  92. Set oldFile = Nothing
  93. Set oFS = Nothing
Aug 2 '12 #1
2 27857
twinnyfo
3,653 Expert Mod 2GB
Thanks, Rabbit! I always wondered how they did that... Now we all can be super secret squirrels!
Aug 2 '12 #2
Frinavale
9,735 Expert Mod 8TB
I remember reading about the history of Steganography...

I remember one of the first usages of it.

There was of a slave who had their head shaved. A message tattooed to their scalp and their hair was left to grow back in. Once the hair was back, the slave was was sent to deliver the message.
Aug 2 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ThoughtProvoker | last post by:
Ive recently migrated for Visual Basic 6.0 to VB.NET and ive exprerience of many skills of it and recently i am trying to perform Least Significant Bit Steganography in it and im unable to do so...
2
by: coolwarrior | last post by:
Hi, 1_I want to know the difference between "data hiding" , "steganography" ,"watermarking" ,"capsulation" related to DSP. 2_There r plenty of informaion about data hiding for images on the web...
1
by: Maqsood Ahmed | last post by:
Hello, Does anyone have any idea that how can I store extra information in an image. such as text, as a part of image. I don't want to show the text in an image but I want to store this...
4
by: eldjon | last post by:
does anyone know how can we hide the information of a binary picture in a normal RGB picture in a way that this changes will not be visuable ?
1
by: radix2 | last post by:
hello, anybody can help me to make application encryption(using AES 256 bit)+steganography(using LSB insertion technique)...thanks before..i really need help....
1
by: ctmashidayu | last post by:
how to code using C++ -security information hiding in an image? anybody know?
12
by: gaya3 | last post by:
Hi All, I'm trying to encrypt the message in the gif image. is there any algorithm for that to do? I'm able to get create new image ,and even i retrieved the byte of the image. ...
2
Rafael Justo
by: Rafael Justo | last post by:
Hi, I'm developing a library to manage passwords and hide them in images. For now I'm using stepic, but this library only allows BMP images (easy to find info). I was wondering if there's any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.